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();
}