YuezhenQin / javase

Implement Data Structures and Algorithms (Sorting, Searching, Greedy, DP) from Sketch
2 stars 1 forks source link

BinarySearch #15

Closed YuezhenQin closed 11 months ago

YuezhenQin commented 11 months ago
YuezhenQin commented 6 months ago

BinarySearch On Arrays (Search Spaces)

Solution704. Solution74.

BinarySearch On Solution Spaces

When a problem wants you to find the min/max, it wants you to find the threshold where the task transitions from impossible to possible.

First, we establish the possible solution space by identifying the minimum possible answer as left and the maximum possible answer right.

Next, we binary search on this solution space. For each mid, we perform a check() to see if the task is possible. Depending on the result, we halve the search space. Eventually, we will find the threshold.

Solution875.