Dichotomy Method for Solving the Optimum Problem of Bounded Interval
Recently, I encountered several problems on leetcode that were solved by dichotomy. I summarized the rules. To put it simply, if you want to find the maximum or minimum value that meets the conditions from a bounded interval, you can Consider using a dichotomy, but it is not the basic dichotomy, but a dichotomy that keeps looking for the left boundary or the right boundary.
For the dichotomy of finding the left boundary or the right boundary, see my previous blog:魔鬼的二分查找
The link to the example is: https://leetcode.cn/problems/maximum-value-at-a-given-index-in-a-bounded-array/
The personal problem-solving code is:
1 | /** |