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

Sockets - Kirsten #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions lib/matrix_convert_to_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,45 @@
# If any number is found to be 0, the method updates all the numbers in the
# corresponding row as well as the corresponding column to be 0.

# Time complexity: ?
# Space complexity: ?
# Time complexity: O(m * n), where m is the number of rows in the input matrix and n is the number of columns
# Space complexity: O(m + n), where m is the number of rows in the input matrix and n is the number of columns
def matrix_convert_to_zero(matrix)
raise NotImplementedError
x_zeroes = {}
y_zeroes = {}

rows = matrix.length
columns = matrix[0].length

i = 0
until i == rows
array = matrix[i]

j = 0
until j == columns
if array[j] == 0
x_zeroes[i] = true
y_zeroes[j] = true
end
j += 1
end
i += 1
end

rows.times do |row|
if x_zeroes[row] == true
columns.times do |column|
matrix[row][column] = 0
end
end
end

columns.times do |column|
if y_zeroes[column] == true
rows.times do |row|
matrix[row][column] = 0
end
end
end

return matrix
end