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 - Amy #12

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
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 = []

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|

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