371. Partition List
MediumLinked List
Rearrange the list so all nodes less than x come before nodes ≥ x, keeping the original relative order in each part. Print the list.
Input format
Line 1: n x Line 2: n values
Output format
The partitioned list.
Example 1
Input
6 3 1 4 3 2 5 2
Output
1 2 2 4 3 5
Example 2
Input
2 2 2 1
Output
1 2
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…