package leetcode;

/**
 * https://leetcode.com/problems/longest-happy-string/
 */
public class Problem1405 {
    public String longestDiverseString(int a, int b, int c) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1405 prob = new Problem1405();
        System.out.println(prob.longestDiverseString(1, 1, 7)); // "ccaccbcc"
        System.out.println(prob.longestDiverseString(1, 1, 10)); // "ccaccbcc"
        System.out.println(prob.longestDiverseString(2, 2, 1)); // "aabbc"
        System.out.println(prob.longestDiverseString(7, 1, 0)); // "aabaa"
        System.out.println(prob.longestDiverseString(5, 6, 7)); // "ccbbaaccbbaaccbbac"
    }
}

@@ -12,16 +12,49 @@
 tcode;%0A%0A
+import java.util.PriorityQueue;%0A%0A
 /**%0A * h
@@ -209,529 +209,1399 @@
     
-// TODO%0A        return null;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1405 prob
+PriorityQueue%3CCharCount%3E queue = new PriorityQueue%3C%3E(%0A            (e1, e2) -%3E Integer.compare(e2.count, e1.count));%0A        if (a %3E 0) %7B%0A            queue.add(new CharCount('a', a));%0A        %7D%0A        if (b %3E 0) %7B%0A            queue.add(new CharCount('b', b));%0A        %7D%0A        if (c %3E 0) %7B%0A            queue.add(new CharCount('c', c));%0A        %7D%0A        StringBuilder answer = new StringBuilder();%0A        CharCount prev
  = n
-ew Problem1405();%0A        System.out.println(prob.longestDiverseString(1, 1, 7)); // %22ccaccbcc%22%0A        System.out.println(prob.longestDiverseString(1, 1, 10)); // %22ccaccbcc%22%0A        System.out.println(prob.longestDiverseString(2, 2
+ull;%0A        while (!queue.isEmpty()) %7B%0A            CharCount current = queue.poll();%0A            if (prev != null && current.ch == prev.ch && prev.count == 2) %7B%0A                if (queue.isEmpty()) %7B%0A                    break;%0A                %7D%0A                CharCount next = queue.poll();%0A                queue.add(current);%0A                current = next;%0A            %7D%0A            answer.append(current.ch);%0A            current.count--;%0A            if (current.count %3E 0) %7B%0A                queue.add(current);%0A            %7D%0A            if (prev != null && prev.ch == current.ch) %7B%0A                prev.count++;%0A            %7D else %7B%0A                prev = new CharCount(current.ch
 , 1)
-); // %22aabbc%22%0A        System.out.println(prob.longestDiverseString(7, 1, 0)); // %22aabaa%22%0A        System.out.println(prob.longestDiverseString(5, 6, 7)); // %22ccbbaaccbbaaccbbac%22
+;%0A            %7D%0A        %7D%0A        return answer.toString();%0A    %7D%0A%0A    private static class CharCount %7B%0A        private final char ch;%0A        private int count;%0A%0A        public CharCount(char ch, int count) %7B%0A            this.ch = ch;%0A            this.count = count;%0A        %7D
 %0A   

Solve problem 1405