Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Flip Columns SRBD Coding interview
- #include<bits/stdc++.h>
- using namespace std;
- class solution{
- public:
- int toggle(int n, int m, int k)
- {
- int v[15];
- memset(v, 0, sizeof(v));
- map<int, int>mp;
- for(int i=0; i<n; i++)// row
- {
- for(int j=0; j<m; j++)// col
- {
- int x;
- cin >> x;
- if(x==1)
- {
- v[i]=v[i] | (1<<j); // unique value for a row if all of the 1 position in simillar poisition it will be same like if first row having 1 0 0 and third row 1 0 0 their value will be same
- }
- }
- }
- for(int i=0; i<n; i++)
- {
- mp[v[i]]++;// counting frequency how many simillar value on v array like in input 1st and third one frequency will be same 2nd one will be diffrent
- }
- int mx=0;
- for(auto & [a, b] : mp) //[key, vlaue] in key unique number for specific row and value is how many times it occured
- {
- int x=m-__builtin_popcount(a); // counting how many zero in one row
- if(x<=k and (k-x)%2==0)
- {
- mx=max(mx, b);
- }
- }
- /*for(auto it=mp.begin(); it!=mp.end(); it++)
- {
- int a=it->first;
- int b=it->second;
- int x=m-__builtin_popcount(a); // counting how many zero in one row
- if(x<=k and (k-x)%2==0)
- {
- mx=max(mx, b);
- }
- }*/
- return mx;
- }
- };
- int main()
- {
- solution sol;
- int n, m, k;
- cin >> n >> m >> k;
- cout << sol.toggle(n, m, k) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement