Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Treat the matrix as one virtual sorted array of length rows*cols. Use a single binary search with index mapping: row = floor(mid / cols), col = mid % cols. Compare the mapped value to the target.
The entire matrix is effectively one sorted array. Map virtual index to row/col: row = floor(mid / cols), col = mid % cols.
Updated Feb 2026