class Solution {
public int leastInterval(char[] tasks, int n) {
int len = tasks.length;
int[] arr = new int[26];
for(char c : tasks){
++arr[c - 'A'];
}
Arrays.sort(arr);
int max = arr[25];
int num = 0;
int count = 0;
for(int i = 25;i >= 0;i--){
if(arr[i] < arr[25]){
break;
}
count++;
}
return Math.max((arr[25] - 1) * (n + 1) + count,len);
}
}