Advertisement
nikunjsoni

621

Mar 31st, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement