Stable partition by pivot
Given an integer array values and an integer pivot, rearrange the array so that every element strictly less than pivot comes before every element greater than or equal to pivot, while preserving the original relative order inside each of the two groups (a stable partition). Return the rearranged array. A two-pass approach with a write pointer per group is fine. Example: values = [8, 3, 9, 2, 7], pivot = 7 gives [3, 2, 8, 9, 7].
Implement
stable_partition_below(values: list[int], pivot: int) → list[int]Examples
in
[[8,3,9,2,7],7]out[3,2,8,9,7]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 13 min
solution.py
InputExpectedGot
[[8,3,9,2,7],7][3,2,8,9,7]not run yetsample