package leetcode;

/**
 * https://leetcode.com/problems/reduction-operations-to-make-the-array-elements-equal/
 */
public class Problem1887 {
    public int reductionOperations(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1887 prob = new Problem1887();
        System.out.println(prob.reductionOperations(new int[]{5,1,3})); // 3
        System.out.println(prob.reductionOperations(new int[]{1,1,1})); // 0
        System.out.println(prob.reductionOperations(new int[]{1,1,2,2,3})); // 4
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.Map;%0Aimport java.util.TreeMap;%0A%0A
 /**%0A * h
@@ -245,32 +245,727 @@
     
-// TODO%0A        return 0
+TreeMap%3CInteger, Integer%3E map = new TreeMap%3C%3E((a, b) -%3E Integer.compare(b, a));%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            map.put(nums%5Bi%5D, map.getOrDefault(nums%5Bi%5D, 0) + 1);%0A        %7D%0A        int answer = 0;%0A        while (map.size() %3E 1) %7B%0A            Map.Entry%3CInteger, Integer%3E largestEntry = map.pollFirstEntry();%0A            Map.Entry%3CInteger, Integer%3E nextLargest = map.firstEntry();%0A            map.put(nextLargest.getKey(), nextLargest.getValue() + 1);%0A            int largestEntryCount = largestEntry.getValue() - 1;%0A            if (largestEntryCount %3E 0) %7B%0A                map.put(largestEntry.getKey(), largestEntryCount);%0A            %7D%0A            answer++;%0A        %7D%0A        return answer
 ;%0A  

Update problem 1887