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

Rivera, Leanne DONE #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

leannerivera
Copy link

@leannerivera leannerivera commented Nov 1, 2018

Time complexity: O9n) linear, as it is dependent on how many rows and columns must be converted from 1s to 0s

Space complexity: O(n) linear, as it is dependent on the number of zeros in each row and column of the matrix

@shrutivanw
Copy link

Nice work!

While explaining time and space complexities in terms of n, always explain what n is in the input. If n is the number of rows multiplied by number of columns in the input matrix, then your explanation is correct. I would however encourage you to explain the time complexity in terms of the number of rows and the number of columns.

So, if there are n rows and m columns in the input matrix, then your current algorithm will have the space complexity of O(n*m). You could optimize the space complexity further by maintaining two separate arrays: one array which is n row to track which rows should be converted to 0 and another which is m long to track which columns should be converted to zero. Here's my attempt at such an approach: https://github.com/Ada-C10/matrix_convert_to_zero/blob/solution-basic/lib/matrix_convert_to_zero.rb

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