The problem. Search for a target in an m × n matrix where each row is sorted left to right and each column is sorted top to bottom. Unlike the previous problem, a row doesn't have to start after the previous row ends. Return true if the target is there.
matrix = [[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]]
target = 5 -> true
target = 20 -> falseMembers only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson