14. Find duplicate rows in a binary matrix
The problem can be found at the following link: Question Link
My Approach
We iterate through each row of the matrix.
For each row, we convert it into a string representation where
1
represents a set bit, and0
represents an unset bit.We check if the string representation is already present in our unordered_map.
If it is present, we add the current row index to the
output
vector.If it is not present, we add the string representation to the unordered_map.
Time and Auxiliary Space Complexity
Time Complexity :
O(M * N)
, where M is the number of rows and N is the number of columns in the matrix.Auxiliary Space Complexity :
O(M * N)
for the unordered_map, where M is the number of rows and N is the number of columns.
Code (C++)
Contribution and Support
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the getlost01/gfg-potd repository.
Last updated