Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Danielle - Zero Matrix Methods #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

danimetz
Copy link

Time Complexity: O(2n*m)
Space Complexity: O(n+m)

@shrutivanw
Copy link

Nice work!
👍

You're on the right track. There is one consideration that your current algorithm is missing.
Consider this test case:
The input, original matrix is:

1 1 1 0 0
1 1 1 1 1
1 0 1 1 1
1 1 1 1 1

Manually visualizing this matrix, the matrix is expected to be changed to:

0 0 0 0 0
1 0 1 0 0
0 0 0 0 0
1 0 1 0 0

Your algorithm converts it to:

0 0 0 0 0
1 0 1 0 1
0 0 0 0 0
1 0 1 0 1

To account for this and some other scenarios, I added more test cases to the spec file this morning:

    it "not all rows, not all columns" do
      # setup
      rows = 4
      columns = 5
      matrix = initialize_matrix(rows, columns)
      matrix[0][3] = 0 # row 0, column 1
      matrix[0][4] = 0 # row 1, column 1
      matrix[2][1] = 0 # row 2, column 1
      rows_array = [0, 2]
      columns_array = [1, 3, 4]

      # method call
      matrix_convert_to_0(matrix)

      # validation
      verify_matrix(matrix, rows_array, columns_array)
    end

Hint: your algorithm is breaking too soon and not accounting for the last column needing to be converted to zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants