Matrix = [ [1,0,1], [0,0,1 ], [1,0,1 ]]
Result = [ [1,0,1], [0,0,1] ].
The row [1,0,1] is before [0,0,1] as it appears before in matrix.
The first line of input contains an integer 'T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains two single space-separated integers ‘N’, ‘M’, denoting the number of rows and number of columns in the matrix, respectively.
The next ‘N’ lines of each test case contain ‘M’ space-separated integers denoting the elements of the binary matrix.
For each test case, print all the unique rows in the order they appear in the matrix.
The output for each test case will be printed in a separate line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 3000
1 <= M <= 40
where ‘N’ and ‘M’ are the number of rows and columns of the matrix, respectively.
Time Limit: 1 sec.
We store all the result array ANS. We create an unordered set UNIQUE to store a decimal representation of all rows. Iterate over all the rows in the matrix. If the row is not in the set add it to the set and append it to the ANS.
The algorithm will be-
We will iterate over all the rows in the matrix and store them in the trie. When a new row that is not present in trie appears append it to the ANS. To store a row in trie go through the row if the current element in a row is 0 go to the left child and if it is 1 go to the right child.
To know more about trie data structure: link
The algorithm will be-
LRU Cache
Longest Subarray With Zero Sum
Search In A Sorted 2D Matrix
Spiral Matrix
Spiral Matrix
Spiral Matrix
Maximum GCD