Partitioning · Easy
A triage display groups measurements below, equal to and above a threshold. Within each group it must retain arrival order so an operator can still follow the sequence. This is stable classification, not a numeric sort.
Return three ordered groups around the threshold while preserving every input occurrence.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ nums: integer[], target: integer }
Fields
- nums is an array of signed integers. Repeated values at different positions are separate entries.
- target is an integer between -2000000000 and 2000000000.
Output
Return value
- Return [less,equal,greater], each an array. Every input occurrence belongs to exactly one group.
- Preserve original relative order inside every group. Empty groups are represented by [].
Constraints
- 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
- All totals and counts fit exactly in a safe JSON integer.
Examples
Example 1
{
"nums": [
7,
2,
5,
6,
5,
1
],
"target": 5
}Returns
[
[
2,
1
],
[
5,
5
],
[
7,
6
]
]Example 2
{
"nums": [
3,
3
],
"target": 3
}Returns
[
[],
[
3,
3
],
[]
]Required complexity
O(n) time and O(n) output space