As reported: ServiceNow Senior Software Engineer loop, round 1 (coding), Apr 2025: this problem, a short project discussion, and the approach for ranking users by words written in a log.
Each row of the m × n matrix is sorted left to right and each column top to bottom. Return whether target occurs in it.
This is LeetCode 240 — Search a 2D Matrix II.
Example
[[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 -> false
Constraints: 1 ≤ m, n ≤ 300; -10^9 ≤ values, target ≤ 10^9.
Code runner format: line 1 matrix, line 2 target. Implement searchMatrix(matrix, target); the harness prints true or false.