Skip to content
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
28 changes: 27 additions & 1 deletion lib/matrix_convert_to_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,31 @@
# Time complexity: ?
# Space complexity: ?
def matrix_convert_to_zero(matrix)
raise NotImplementedError
new_matrix = []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think the space & time complexities are?

rows_w_0 = {}
cols_w_0 = {}

matrix.length.times do |x|
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely works, but you could also use the 0th index of the row and columns to serve the same role as the rows_w_0 and cols_w_0 arrays.

matrix[x].length.times do |y|
if matrix[x][y] == 0
rows_w_0[x] = true
cols_w_0[y] = true
end
end
end

matrix.length.times do |x|
matrix[x].length.times do |y|
if rows_w_0[x] == true || cols_w_0[y] == true
matrix[x][y]=0
else
end
end
end
return matrix
end