Ashish and Binary Matrix

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 nint mvector<string&v)
{
    set<stringst;
    for (int i = 0i < ni++)
    {

        st.insert(v[i]);
    }
    if (st.size() == n)
        cout << "Yes\n";
    else
        cout << "No\n";
}
int main()
{

    int n = 3m = 3;
    vector<stringv = {"101",
                        "000",
                        "100"};
    binaryMatrix(nmv);

    return 0;
}


No comments:

Post a Comment