Skip to content

Latest commit

 

History

History
20 lines (19 loc) · 599 Bytes

74.md

File metadata and controls

20 lines (19 loc) · 599 Bytes

Task Scheduler

LeetCode Link

    int leastInterval(vector<char>& tasks, int n) {
        // calculate the frequency of each character
        vector<int>frequency(26,0);
        int count=0;
        for(int i=0;i<tasks.size();i++){
            frequency[tasks[i]-'A']++;
            count=max(count,frequency[tasks[i]-'A']);
        }

        int ans=(count-1)*(n+1);
        for(int i=0;i<26;i++){
            if(frequency[i]==count){
                ans++;
            }
        }
        return ans>tasks.size()?ans:tasks.size();
    }