Implement 3-way partition QuickSort for duplicates
Analyze the implement 3-way partition quicksort for duplicates.
Examples
Input:"test_input_1"
Output:"output_1"
Input:"test_input_2"
Output:"output_2"
Hints
Recall how the standard 2-way partition (Lomuto or Hoare) handles duplicates and why it can degrade to O(n²) when many duplicates exist.
Consider how a 3-way partition (Dutch National Flag) divides the array into three regions: elements less than, equal to, and greater than the pivot.
Design the partitioning logic to place all duplicates of the pivot into their correct final positions in a single pass, ensuring O(n) time for the partitioning step.
Implement 3-way partition QuickSort for duplicates
Analyze the implement 3-way partition quicksort for duplicates.