package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/
 */
public class Problem1365 {
    public int[] smallerNumbersThanCurrent(int[] nums) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1365 prob = new Problem1365();
        System.out.println(Arrays.toString(prob.smallerNumbersThanCurrent(new int[]{8,1,2,2,3}))); // [4,0,1,1,3]
        System.out.println(Arrays.toString(prob.smallerNumbersThanCurrent(new int[]{6,5,4,8}))); // [2,1,0,3]
        System.out.println(Arrays.toString(prob.smallerNumbersThanCurrent(new int[]{7,7,7,7}))); // [0,0,0,0]
    }
}

@@ -36,16 +36,64 @@
 .Arrays;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -277,468 +277,466 @@
     
-// TODO%0A        return null
+int%5B%5D sorted = Arrays.copyOf(nums, nums.length);%0A        Arrays.sort(sorted)
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1365 prob = new Problem1365();%0A        System.out.println(Arrays.toString(prob.smallerNumbersThanCurrent(new int%5B%5D%7B8,1,2,2,3%7D))); // %5B4,0,1,1,3%5D%0A        System.out.println(Arrays.toString(prob.smallerNumbersThanCurrent(new int%5B%5D%7B6,5,4,8%7D))); // %5B2,1,0,3%5D%0A        System.out.println(Arrays.toString(prob.smallerNumbersThanCurrent(new int%5B%5D%7B7,7,7,7%7D))); // %5B0,0,0,0%5D
+Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C sorted.length; i++) %7B%0A            if (!map.containsKey(sorted%5Bi%5D)) %7B%0A                map.put(sorted%5Bi%5D, i);%0A            %7D%0A        %7D%0A        int%5B%5D answer = new int%5Bnums.length%5D;%0A        for (int i = 0; i %3C nums.length; i++) %7B%0A            answer%5Bi%5D = map.get(nums%5Bi%5D);%0A        %7D%0A        return answer;
 %0A   

Solve problem 1365