Matrix search (giving two test cases error)

see you are getting error because while taking input in the second for loop you have written j<n but it should be j<m

your codes complexity is m*n…but you can further optimize it to log(m+n)

affter solving this issue , it is again giving second test case wrong

share the link of modified code here