Given a matrix mat having n rows and m columns. We need to find unique elements in matrix i.e, those elements which are not repeated in the matrix or those elements whose frequency is 1.
Input : 20 15 30 2 2 3 5 30 6 7 6 8 Output : 3 20 5 7 8 15 Input : 1 2 3 5 6 2 1 3 5 6 2 2 Output : No unique element in the matrix
Follow these steps to find unique element:
1. Create an empty hash table or dictionary.
2. Traverse through all the elements of the matrix
3. If element is present in the dictionary, then increment its count
4. Otherwise insert element with value = 1.
2 7 8 25 15
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find sum of all elements in a matrix except the elements in row and/or column of given cell?
- Find the sum of the diagonal elements of the given N X N spiral matrix
- Find a Square Matrix such that sum of elements in every row and column is K
- Given a Boolean Matrix, find k such that all elements in k'th row are 0 and k'th column are 1.
- Find the sum of elements of the Matrix generated by the given rules
- Find distinct elements common to all rows of a matrix
- Program to find the Product of diagonal elements of a matrix
- Construct a unique matrix n x n for an input n
- Maximum sum of a Matrix where each value is from a unique row and column
- Unique cells in a binary matrix
- Print unique rows in a given boolean matrix
- Python | Print unique rows in a given boolean matrix using Set with tuples
- Check if the rows of a binary matrix can be made unique by removing a single column
- Program to print elements of a Matrix row-wise skipping alternate elements
- Minimum difference between adjacent elements of array which contain elements from each row of a matrix
- Move matrix elements in given direction and add elements with same value
- Program to swap upper diagonal elements with lower diagonal elements of matrix.
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Maximum sum of elements from each row in the matrix
- Sum of all odd frequency elements in a Matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.