Try to solve the problem in 'Single Scan'. ' Single Scan' refers to iterating over the array/list just once or to put it in other words, you will be visiting each element in the array/list just once.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains an Integer 'N' denoting the size of the array/list.
The second line of each test case contains 'N' space-separated Integers denoting the array/list.
For each test case/query, print the sorted array/list(ARR) as space-separated Integers.
Output for every test case will be printed in a separate line.
You need to change in the given array/list itself. Hence, no need to return or print anything.
1 <= T <= 10
1 <= N <= (5 * (10 ^ 5))
0 <= ARR[i] <= 2
Where 'N' is the size of the given array/list.
And, ARR[i] denotes the i-th element in the array/list.
Time Limit: 1sec
We can exploit the property that we will only have 0s, 1s and 2s in our array.
We’ll use a three-pointer approach to solve this problem
Longest Subarray With Zero Sum
Merge Two Sorted Arrays Without Extra Space
Ninja And The Strictly Increasing Array
Negative To The End
Sort 0s, 1s, 2s