


The first line contains three integers, ‘X’, ‘N’, and ‘M’, separated by a single space denoting the element to be searched, the number of rows in the matrix, and the number of columns in the matrix, respectively.
The next ‘N’ lines contain ‘M’ integers, each denoting the elements of the matrix.
Print “Yes”(without quotes) if ‘X’ is present in the matrix; otherwise, print “No”.
You don’t need to print anything; It has already been handled.
1 <= X <= 10^6
1 <= N,M <= 100
-10^6 <= ARR[i][j] <= 10^6
Where ARR[i][j] denotes the jth element of the i’th row of the given matrix.
Time Limit: 1 sec
The idea is to iterate through the matrix and check if any element is equal to ‘X’.
The steps are as follows :
The idea is to use the property of sorted rows of the matrix and apply binary search on each row.
The steps are as follows :
The idea is to use the fact that each row is sorted and that each column is sorted. We will use the 2 pointer approach to solve the question.
The steps are as follows :