Advertisement
Mohammad_Dipu_Sultan

Untitled

May 26th, 2023
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. // Flip Columns SRBD Coding interview
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. class solution{
  6.  
  7.     public:
  8.         int toggle(int n, int m, int k)
  9.         {
  10.             int v[15];
  11.             memset(v, 0, sizeof(v));
  12.             map<int, int>mp;
  13.             for(int i=0; i<n; i++)// row
  14.             {
  15.                 for(int j=0; j<m; j++)// col
  16.                 {
  17.                     int x;
  18.                     cin >> x;
  19.                     if(x==1)
  20.                     {
  21.                         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
  22.                     }
  23.                 }
  24.             }
  25.  
  26.             for(int i=0; i<n; i++)
  27.             {
  28.                 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
  29.             }
  30.             int mx=0;
  31.             for(auto & [a, b] : mp) //[key, vlaue] in key unique number for specific row and value is how many times it occured
  32.             {
  33.                 int x=m-__builtin_popcount(a); // counting how many zero in one row
  34.  
  35.                 if(x<=k and (k-x)%2==0)
  36.                 {
  37.                     mx=max(mx, b);
  38.                 }
  39.             }
  40.  
  41.             /*for(auto it=mp.begin(); it!=mp.end(); it++)
  42.             {
  43.                 int a=it->first;
  44.                 int b=it->second;
  45.                 int x=m-__builtin_popcount(a); // counting how many zero in one row
  46.  
  47.                 if(x<=k and (k-x)%2==0)
  48.                 {
  49.                     mx=max(mx, b);
  50.                 }
  51.             }*/
  52.  
  53.             return mx;
  54.         }
  55.  
  56.            
  57. };
  58. int main()
  59. {
  60.     solution sol;
  61.  
  62.     int n, m, k;
  63.     cin >> n >> m >> k;
  64.    
  65.     cout << sol.toggle(n, m, k) << endl;
  66.  
  67.     return 0;
  68. }
Tags: SRBD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement