Data Structures & AlgorithmsHardProduct Company SDE · binary search round

Problem: What is the worst-case time complexity of binary search for the first occurrence of a value in a sorted array that contains duplicates?

  1. A. O(n)
  2. B. O(log n)
  3. C. O(n log n)
  4. D. O(sqrt n)

Correct answer: B. O(log n)

A modified binary search that keeps searching left after a match finds the first occurrence in O(log n) comparisons.

More Coding Interview Problems questions

Exams that ask this topic