Data Structures & AlgorithmsHardInfosys SP/DSE · Product Company SDE

Problem: A problem is solved via binary search on the answer (not on an array index) -- e.g. 'minimum capacity to ship packages within D days'. What property must the problem have for this technique to apply?

  1. A. The input array must already be sorted
  2. B. The answer must always be an array index
  3. C. The feasibility check (can we achieve X?) must be monotonic in X: if X works, every larger (or smaller, depending on direction) value also works
  4. D. There must be no feasible answer at all

Correct answer: C. The feasibility check (can we achieve X?) must be monotonic in X: if X works, every larger (or smaller, depending on direction) value also works

Binary search on the answer relies on a monotonic predicate: once a candidate value is feasible, every value past it in the same direction stays feasible (or infeasible), letting binary search narrow in on the boundary.

More Coding Interview Problems questions

Exams that ask this topic