Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: Lomuto partition uses the last element as the pivot on [3, 8, 2, 5, 1, 4, 7, 6]. After one partition pass, at what index (0-based) is the pivot placed?

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

Correct answer: D. 5

Lomuto partition keeps a boundary of values not greater than the pivot and finally swaps the pivot into the boundary position. Using the first element as the pivot gives a different final index.

More Coding Interview Problems questions

Exams that ask this topic