Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: The array [5, 3, 8, 6, 2, 7] is processed by the partition step of quicksort with pivot = first element (5), using the Hoare-style pivot exchange: count the elements strictly less than the pivot that lie to its right of the pivot's final boundary. Report that count.

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

Correct answer: B. 2

The number of elements smaller than the pivot determines where the pivot lands in the partition. Here 3 and 2 are smaller than 5, so the count is two.

More Coding Interview Problems questions

Exams that ask this topic