values. Its numbers are dealt, in order, into two piles, a left one and a right one:
- the first number goes to the left pile, the second to the right pile;
- each following number x goes to the pile that holds **more** numbers strictly greater than x;
- if both piles hold equally many such numbers, x goes to the pile that is currently smaller;
- if the sizes are equal too, it goes to the left pile.
Each number is appended to the end of its pile. Return the left pile followed by the right pile as a single array.values=[4, 6, 5, 1, 5] → [4, 6, 5, 1, 5]
Left pile [4], right pile [6]. For 5: 0 larger on the left, 1 on the right, so it goes right. For 1: 1 vs 2, right again. For 5: 0 vs 1, right. Result: [4] + [6, 5, 1, 5].
values=[2, 2, 2, 2] → [2, 2, 2, 2]
Nothing is ever larger, so each number goes to the shorter pile, and to the left one on a tie: [2, 2] + [2, 2].
values=[9, 3, 7, 8] → [9, 7, 8, 3]
values) ≤ 10⁵values[i] ≤ 10⁹values=[4, 6, 5, 1, 5]
[4, 6, 5, 1, 5]
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.