Binary Search on Answer (Twisted Problem)

viaLeetCode

Problem: A coding problem with a "slightly twisted" statement, solved using the Binary Search on Answer technique (binary searching over the space of possible answers rather than over an array).

Approach: Identify that the answer space is monotonic with respect to some feasibility check (i.e., if X works then everything on one side of X also works). Binary search over the answer range, using a feasibility function (typically O(n) or O(n log n)) to decide whether to move the search bounds left or right, converging on the minimal/maximal valid answer in O(log(range) * feasibility-check-time).

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account