
If the given list is [ [ 4, 2], [ 6, 1 ], [ 10, 0 ], [ 1, 1] ].
The correct order should be [ [ 10, 0 ], [ 1, 1 ], [
6, 1 ], [ 4, 2 ] ].
A person with a height of ‘10’ has ‘0’ persons in front with a height more than ‘10’. So this person should be in the first place.
A person with a height of ‘1’ has ‘1’ person with a height of more than 1, so it is placed after [10,0].
A person with a height of ‘6’ has ‘1’ person in front with a height more than ‘ 6 ’.So this should be at the third position as 10 > 6.
A person with a height of ‘ 4 ’ has ‘2’ persons in front with a height more than ‘ 4 ‘.So this should be at the last position as 10 > 4 and 6 > 4.
The first line contains ‘T’, denoting the number of test cases to be performed.
The first line of each test case contains an integer ‘N’ indicating the number of persons.
Then 'N' lines follow. Each line represents the elements of the 'N' x 2 matrix where each row denotes the two attributes value.
For each test case, return the rearranged 'N' x 2 matrices having all the persons at their correct position.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^3
1 <= ATTRIBUTES[ i ][ 0 ] <= 10^5
1 <= ATTRIBUTES[ i ][ 1 ] <= N
Time Limit: 1 sec
Algorithm:
Parent of element in BIT at index ‘ i ‘ can be found at ( i + ( i & - i ) .) index
Child of the element in BIT at index ‘ i ‘ can be found at ( i - ( i & -i ) ) index.
Algorithm