240. Search a 2D Matrix II
Medium
Problem:
Implement an efficient algorithm to find a value in an m×n matrix. The matrix is sorted in ascending order from left to right and from top to bottom.

https://leetcode.com/problems/search-a-2d-matrix-ii/
What to learn:
Built-in Python functions: any() and all()
any() and all()any(): It's similar to the logical OR operation.all(): It's similar to the logical AND operation.
Start with the last element of the first row. If the target is smaller than this, move to the left. If it's larger, move downward.
We can also start the search from the bottom-left corner of the matrix. At each step, the idea is to move either upward (if the current element is less than the target) or to the right (if the current element is greater than the target).
Pythonic way
Internally, Python will likely search the matrix for the presence of a value, one row at a time from the top.
Last updated