package leetcode;

/**
 * https://leetcode.com/problems/increasing-decreasing-string/
 */
public class Problem1370 {
    public String sortString(String s) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1370 prob = new Problem1370();
        System.out.println(prob.sortString("aaaabbbbcccc")); // "abccbaabccba"
        System.out.println(prob.sortString("rat")); // "art"
        System.out.println(prob.sortString("leetcode")); // "cdelotee"
        System.out.println(prob.sortString("ggggggg")); // "ggggggg"
        System.out.println(prob.sortString("ggggggg")); // "ggggggg"
        System.out.println(prob.sortString("spo")); // "ops"
    }
}

@@ -12,16 +12,94 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.TreeMap;%0A%0A
 /**%0A * h
@@ -241,35 +241,732 @@
     
-// TODO%0A        return null
+TreeMap%3CCharacter, Integer%3E map = new TreeMap%3C%3E();%0A        for (int i = 0; i %3C s.length(); i++) %7B%0A            map.put(s.charAt(i), map.getOrDefault(s.charAt(i), 0) + 1);%0A        %7D%0A        String answer = %22%22;%0A        boolean asc = true;%0A        while (map.size() %3E 0) %7B%0A            List%3CCharacter%3E keys = asc ?%0A                new ArrayList%3C%3E(map.keySet()) : new ArrayList%3C%3E(map.descendingKeySet());%0A            for (char key : keys) %7B%0A                answer += key;%0A                int c = map.get(key) - 1;%0A                if (c == 0) %7B%0A                    map.remove(key);%0A                %7D else %7B%0A                    map.put(key, c);%0A                %7D%0A            %7D%0A            asc = !asc;%0A        %7D%0A        return answer
 ;%0A  

Update problem 1370