Failing perf-test-12

All the test cases are passing except perftest-12. It has a Timeout error.
Help me with optimizing the code.

Did you get testcases to download, it should have been available on the right pullout bar (accessible via the little bulb icon)?

It’s a little hard to give suggestions without any more details. In your case: For search a 2d matrix, what is the time complexity of your problem? Can you try calculating the time complexity of your solution and post it here? The desired time complexity should be O(M log N).

And generally for perf test cases, you should look at other things as well:

  • Are certain parts of your logic unnecessary?
  • Is there any language specific issues slowing it down? (eg: String appending in Java vs using StringBuilder)
  • Are you using references instead of values, otherwise memory is allocated at runtime.

I’m doing binary search either row by row or column by column, and in case if the first element of row or column is greater than target then i’m stopping and returning False.
The complexity is O(M log N)

Desired time complexity is O(M+N) instead of O(M logN) as what is mentioned in debrief. You can try O(M+N) approach and it should work. let us know if you have any doubts with this approach.

but other testcases are passing, except this.

Were you able to reduce the time complexity to O(M+N) for that testcase?

yes. i was able to reduce

Closing this topic as it has been solved by you yourself. Great job, keep working hard. if its not resolved feel free to un-mark the accepted solution to re-open the topic.