Advertisement
nikunjsoni

318

May 27th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxProduct(vector<string>& words) {
  4.         unordered_map<int, int> maskLen;
  5.         int ans = 0;
  6.         for(auto word: words){
  7.             int mask = 0;
  8.             for(char ch: word)
  9.                 mask |= (1<<(ch-'a'));
  10.             maskLen[mask] = max(maskLen[mask], int(word.length()));
  11.            
  12.             for(auto &mLen: maskLen)
  13.                 if(!(mask & mLen.first))
  14.                     ans = max(ans, int(mLen.second*word.length()));
  15.         }
  16.         return ans;
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement