seanchen11235
BAN USER- 4of 4 votes
AnswersGiven an m x n matrix where each row element is sorted, but the columns do not appear in sorted order, write a function to print each matrix element in sorted order.
- seanchen11235 in United States
Example matrix:
matrix = [
[20, 40, 80],
[5, 60, 90],
[45, 50, 55]
]
Your function should print 5, 20, 40, 45, 50, 55, 60, 80, 90.
Add on: Assume that we are space-constrained such that we can only hold one row in memory at a time. Optimize your function to work under such constraints as efficiently as possible.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 3 votes
AnswersGiven a matrix of integers where each row is sorted but the columns are not sorted, print each matrix element in sorted order.
Here's an example matrix:matrix = [ [20, 35, 900], [5, 40, 45], [50, 60, 75] ]
Your function should print:
5, 20, 35, 40, 45, 50, 60, 75, 900
Add on: Assume that we have limited memory such that we can only hold one row in memory at a time. Optimize your algorithm given such constraints.
- seanchen11235 in United States| Report Duplicate | Flag | PURGE
Algorithm