![]() |
VOOZH | about |
Given a matrix mat[][] having n rows and m columns. The task is to find unique elements in the matrix i.e., those elements which are not repeated in the matrix or those elements whose frequency is 1.
Examples:
Input:
mat[][] = [[2, 1, 4, 3],
[1, 2, 3, 2],
[3, 6, 2, 3],
[5, 2, 5, 3]]
Output: 4 6Input:
mat[][] = [[1, 2],
[2, 1]]
Output: No unique element in the matrix
Approach:
The idea is to create an empty hashmap and traverse through all the elements of the matrix and update the count of element in hashmap. After traversal if count of element is 1 it is unique else it is not.
15 8 7 2 25
Time Complexity: O(n*m)
Auxiliary Space: O(n*m)