There are lots of hard difficulty problems in leetcode that is using binary search for a simple solution. The common pattern of these problems are 1) the sequence is sorted. 2) there are limits (explicit or implicit) to the desired output. 3) there is a target (explicit or implicit) that can be binary searched and checked against the limits. One common use case scenario is min-max problems.
668. Kth Smallest Number in Multiplication Table
- The multiplication table is sorted row-wise / column-wise.
- The limit is a known ranking.
- The target is the unknown upper bound of the first kth elements.
Leave a comment