2
public int[] smallerNumbersThanCurrent(int[] nums) {3
int[] sorted = nums.clone();4
int[] res = new int[nums.length]; // result array6
for (int i = 0; i < nums.length; ++i) {7
// binary search it, if there is no duplicates the idx will be how many smaller are there8
int idx = binarySearch(sorted, nums[i]);9
// if there are duplicates, then we need to find the first one presented in the array10
if (idx - 1 >= 0 && sorted[idx - 1] == nums[i]) {11
while (idx >= 0 && sorted[idx] == nums[i]) {16
// As I said before, array of indices(indexes) will be the answer22
// Just simple iterative binary search23
public static int binarySearch(int[] arr, int target) {25
int e = arr.length - 1;29
if (arr[m] == target) {31
} else if (arr[m] > target) {