<awangdev>621. Task Scheduler_1.java
public int leastInterval(char[] tasks, int n) {
        if (tasks == null) return 0;
        
        PriorityQueue<Integer> pq = new PriorityQueue<>(26, Collections.reverseOrder());
        int[] counts = new int[26];
        for (char c : tasks) counts[c - 'A']++;
        for (int i = 0; i < counts.length; i++) {
            if (counts[i] > 0) pq.offer(counts[i]);
        }

        int count = 0;
        while (!pq.isEmpty()) {
            int k = n + 1; 
            List<Integer> list = new ArrayList<>();
            while (k > 0 && !pq.isEmpty()) {
                Integer taskCount = pq.poll();
                if (taskCount-- > 1) list.add(taskCount);
                count++;
                k--;
            }

            pq.addAll(list); 
            if (pq.isEmpty()) break;
            count += k; 
        }
        return count;
    }
public int sample_funcname ( char [ ] var_0 , int var_1 ) {
  if ( var_0 == null ) return 0 ;
  PriorityQueue < Integer > var_9 = new PriorityQueue < > ( 26 , Collections . reverseOrder ( ) ) ;
  int [ ] var_10 = new int [ 26 ] ;
  for ( char var_11 : var_0 ) var_10 [ var_11 - 'A' ] ++ ;
  for ( int var_13 = 0 ;
  var_13 < var_10 . length ;
  var_13 ++ ) {
    if ( var_10 [ var_13 ] > 0 ) var_9 . offer ( var_10 [ var_13 ] ) ;
  }
  int var_16 = 0 ;
  while ( ! var_9 . isEmpty ( ) ) {
    int var_19 = var_1 + 1 ;
    List < Integer > var_22 = new ArrayList < > ( ) ;
    while ( var_19 > 0 && ! var_9 . isEmpty ( ) ) {
      Integer var_24 = var_9 . poll ( ) ;
      if ( var_24 -- > 1 ) var_22 . add ( var_24 ) ;
      var_16 ++ ;
      var_19 -- ;
    }
    var_9 . addAll ( var_22 ) ;
    if ( var_9 . isEmpty ( ) ) break ;
    var_16 += var_19 ;
  }
  return var_16 ;
}
