Data Structures & AlgorithmsHardTCS NQT · Infosys

Stable partition of the list [1, 4, 3, 2, 5, 2] around x = 4 puts every node with value < 4 first, then every node with value >= 4, keeping the relative order inside each group. What value is at position 3 of the result (1-based)?

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

Correct answer: A. 2

The small group is 1, 3, 2, 2 and the large group is 4, 5. Keeping relative order is the point, so the first group is not sorted.

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

Exams that ask this topic