Data Structures & AlgorithmsVery hardGATE CS · competitive programming

A three-way partition (Dutch national flag) with a low pointer, a mid pointer and a high pointer runs on [2, 0, 2, 1, 1, 0]. What is the final array?

  1. A. [0, 0, 2, 2, 1, 1]
  2. B. [0, 0, 1, 1, 2, 2]
  3. C. [2, 2, 1, 1, 0, 0]
  4. D. [0, 1, 1, 0, 2, 2]

Correct answer: B. [0, 0, 1, 1, 2, 2]

After a 2 is swapped to the high end, mid must not advance, because the value swapped in is still unexamined. The result is the sorted order 0s, 1s, 2s.

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

Exams that ask this topic