Stable Array Partition
Updated
Problem statement
You are given an integer array nums and a value pivot. Split the values into two groups.
For this exercise, assume all values strictly less than pivot must appear first, followed by all values greater than or equal to it. Within each group, keep the values in their original order.
Return the two groups together in a new array and leave the input unchanged. Preserve duplicates, and place values equal to the pivot in the second group. An empty input returns an empty array.
Function
stablePartition(nums: int[], pivot: int) → int[]Examples
Example 1
nums = [9,1,5,2,5,7]pivot = 5return = [1,2,9,5,5,7]Values 1 and 2 come first. Both groups retain their input order.
Example 2
nums = [3,2,1,2]pivot = 2return = [1,3,2,2]The value 1 is the only value strictly below 2; equal values belong to the second group.
Example 3
nums = []pivot = 0return = []An empty input has no values to partition.
Constraints
0 <= nums.length <= 1000.-10^9 <= nums[i], pivot <= 10^9.
More Roblox Onsite Interview questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Merge Sorted ArrayDP World · ONSITE INTERVIEW
- Remove Duplicates From Sorted Array In PlaceKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Maximize Distance to the Closest Occupied SeatAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Alternate Positive and Negative ValuesTesla · ONSITE INTERVIEWTesla interview questions
- Sparse Vector Dot Product from TuplesMeta · ONSITE INTERVIEWMeta interview questions
- Make a Sorted Array Unique In PlaceAlpaca · ONSITE INTERVIEW
- Two SumMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Move ZeroesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Rotate an Array to the RightScale AI · ONSITE INTERVIEWScale AI interview questions