What is the problem in my code?It is giving incorrect answer for 2nd case.
https://ide.codingblocks.com/s/221987
Matrix Search:2nd case failing
@56amrut.bhokardankar,
Test case:
4 4
10 20 30 40 15 25 35 45 27 29 37 48 32 33 39 50
29
Correct Answer: 1
Your Answer: 0
Corrected code: https://ide.codingblocks.com/s/221995
Approach :
We will make use of the fact that matrix is row wise and column wise sorted. So if we start from the top right we can observe the fact that if we go in the left direction the numbers decrease and if we go downwards the numbers increase. So we can restrict our search space depending on which index we are currently at. If the number at which we are currently standing is greater than the target number then it is obvious that we can find it on the left side of the current row and if the target is greater than the element at current standing then it is obvious that we can find it towards the bottom in that column where every number is greater.