Given an integer array nums and an integer pivot, rearrange nums so that every element less than pivot comes before every element greater than pivot, and every element equal to pivot sits between them. The relative order of the elements less than pivot, and of the elements greater than pivot, must stay the same as in nums. Return the rearranged array.
Given an integer array nums and an integer pivot, rearrange nums so that every element less than pivot comes before every element greater than pivot, and every element equal to pivot sits between them. The relative order of the elements less than pivot, and of the elements greater than pivot, must stay the same as in nums. Return the rearranged array.
Example 1:
Input: {"nums":[9,12,5,10,14,3,10],"pivot":10}
Output: [9,5,3,10,10,12,14]
Constraints:
1≤nums.length≤105
−106≤nums[i]≤106
pivot equals an element of nums.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[9,12,5,10,14,3,10],"pivot":10}
Fill the answer with the pivot 10. 3 values will land on the left, 2 on the right, and the 2 slots left in the middle already hold the right value.