Problem:
Keep order of positives SAME
Keep order of negatives SAME
Move all negatives to the end
This means:
You need a stable partition
NOT swapping randomly like quicksort
Correct Approach (Simple & Clean)
Idea:
First collect all positive numbers
Then collect all negative numbers
Put back into array
Example
Input:
[1, -1, 3, 2, -7, -5, 11, 6]
Step:
positives → [1, 3, 2, 11, 6]
negatives → [-1, -7, -5]
Final:
[1, 3, 2, 11, 6, -1, -7, -5]


Top comments (0)