VOOZH about

URL: https://www.geeksforgeeks.org/dsa/find-unique-elements-matrix/

⇱ Find unique elements in a matrix - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Find unique elements in a matrix

Last Updated : 19 Dec, 2024

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 6

Input:
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.


Output
15 8 7 2 25 

Time Complexity: O(n*m)
Auxiliary Space: O(n*m)

Comment
Article Tags: