Given a linked list and a key, partition it such that all nodes with values less than key are before it and all nodes with values greater than key are after it.
The relative order of the numbers in each of the partition should be maintained.
Linked list: 1 → 6 → 2 → 4 → 3 → 5 → 2 → 8 → 4 → 7
key: 5
Result: 1 → 2 → 4 → 3 → 2 → 4 → 5 → 6 → 8 → 7
The first line contains an integer ‘T’ denoting the number of independent test cases.
For each test case the input has three lines:
For each test case, a line containing ‘n’ space-separated integers denoting the resultant linked list elements.
2
10
1 6 2 4 3 5 2 8 4 7
5
10
1 6 2 4 3 5 2 8 4 7
8
1 2 4 3 2 4 5 6 8 7
1 6 2 4 3 5 2 4 7 8
1 <= T <= 1000
1 <= n <= 1000
1 <= key <= 1000
1 <= element <= 1000