Search in a Matrix

Find the position of a given key in a 2D matrix in which all rows and columns are sorted.

Statement

Given a 2D array where all elements in any individual row or column are sorted. Find the position of a given key in such a matrix. If the key is not present in the matrix, return (1,1)(-1, -1).

Example

The following example elaborates on this problem:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.