Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: The sorted array [2, 4, 4, 4, 7, 9, 9, 12] is searched with bisect_left and bisect_right. What is bisect_right(a, 4) − bisect_left(a, 4)?

  1. A. 4
  2. B. 2
  3. C. 5
  4. D. 3

Correct answer: D. 3

bisect_right minus bisect_left counts the copies of a value in a sorted list. Here 4 occurs three times.

More Coding Interview Problems questions

Exams that ask this topic