Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

Sum, over the queries x = 3, 6, 9 on the sorted array [1, 3, 3, 5, 8, 9, 12], of the number of elements that are less than or equal to x. What is the total?

  1. A. 14
  2. B. 12
  3. C. 13
  4. D. 7

Correct answer: C. 13

Each count is a bisect_right position, which includes duplicates equal to x. Using bisect_left instead drops the copies equal to 3 from the first query.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic