nikunjsoni

621

Mar 31st, 2021
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int max(int a, int b){
  4.         return (a > b) ? a:b;
  5.     }
  6.    
  7.     int leastInterval(vector<char>& tasks, int n) {
  8.         int maxCount, ans;
  9.         maxCount = ans = 0;
  10.         unordered_map<char, int> m;
  11.        
  12.         for(auto c: tasks){
  13.             m[c]++;
  14.             maxCount = max(maxCount, m[c]);
  15.         }
  16.        
  17.         ans = (maxCount-1)*(n+1);
  18.         for(auto c: m){
  19.             if(c.second == maxCount) ans++;
  20.         }
  21.         ans = max(ans, tasks.size());
  22.         return ans;
  23.     }
  24. };
RAW Paste Data