Pulkit is really good at maths. Recently, he came to know about a problem on matrices. Amazed by the problem he got, he asked Ashish the same problem. Ashish also being good at maths solved the problem within 5 minutes. Now, it's your time to solve the problem.
You will be given n*m binary matrix. You need to tell if it is possible to delete a column such that after deleting that column, rows of the matrix will be unique. If yes then print "Yes" else print "No".
Example:
Input: n = 3, m = 3, v = {"101", "000", "100"}
Output: Yes
Approach
C++
#include <bits/stdc++.h>using namespace std;void binaryMatrix(int n, int m, vector<string> &v){set<string> st;for (int i = 0; i < n; i++){st.insert(v[i]);}if (st.size() == n)cout << "Yes\n";elsecout << "No\n";}int main(){int n = 3, m = 3;vector<string> v = {"101","000","100"};binaryMatrix(n, m, v);return 0;}
No comments:
Post a Comment