Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's&nbsp;such that&nbsp;j != i and nums[j] &lt; nums[i].

Return the answer in an array.

&nbsp;
Example 1:

Input: nums = [8,1,2,2,3]
Output: [4,0,1,1,3]
Explanation: 
For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). 
For nums[1]=1 does not exist any smaller number than it.
For nums[2]=2 there exist one smaller number than it (1). 
For nums[3]=2 there exist one smaller number than it (1). 
For nums[4]=3 there exist three smaller numbers than it (1, 2 and 2).


Example 2:

Input: nums = [6,5,4,8]
Output: [2,1,0,3]


Example 3:

Input: nums = [7,7,7,7]
Output: [0,0,0,0]


&nbsp;
Constraints:


	2 &lt;= nums.length &lt;= 500
	0 &lt;= nums[i] &lt;= 100


class Solution:
    def smallerNumbersThanCurrent(self, nums):
        sortify = sorted(nums)
        return (bisect_left(sortify, i) for i in nums)
class Solution {
    public int[] smallerNumbersThanCurrent(int[] nums) {
        int[] sorted = nums.clone();
        int[] res = new int[nums.length];//result array
        Arrays.sort(sorted);
        for (int i = 0; i < nums.length; ++i) {
            //binary search it, if there is no duplicates the idx will be how many smaller are there
            int idx = binarySearch(sorted, nums[i]);
            //if there are duplicates, then we need to find the first one presented in the array
            if (idx-1>=0 && sorted[idx-1] == nums[i]) {
                while (idx >= 0 && sorted[idx] == nums[i]) {
                    --idx;
                }
                ++idx;
            }
            //As I said before, array of indices(indexes) will be the answer
            res[i] = idx;
        }
        return res;
    }
    //Just simple iterative binary search
     public static int binarySearch(int[] arr, int target) {
        int s = 0;
        int e = arr.length-1;
        int m = (s+e)/2;

        while (s<=e) {
            if (arr[m] == target) {
                return m;
            } else if (arr[m] > target) {
                e = m-1;
            } else {
                s = m+1;
            }
            m = (s+e)/2;
        }
        return -1;
    }
}
class Solution {
public:
    vector<int> smallerNumbersThanCurrent(vector<int>& nums) {
        vector<int> ans;
        int i,j,size,count;
        size = nums.size();
        for(i = 0; i<size; i++){
            count = 0;
            for(j = 0;j<size;j++){
                if(nums[j]<nums[i]) count++;
            }
            ans.push_back(count);
        }
        return ans;
    }
};
var smallerNumbersThanCurrent = function(nums) {
    let count, ans=[];
    /*Run a loop on each element excluding nums[i]
    and compare it with nums[j] if it's large, then count++
    else break;*/
    
    for(let i=0; i<nums.length; i++){
        let temp=nums[i], count=0;
        for(let j=0; j<nums.length; j++){
            if(i===j) continue;
            if(temp>nums[j]) count++;
        }
        ans.push(count);
    }
    return ans;
};

//second way using objects:--->

var smallerNumbersThanCurrent = function(nums) {
    let arr=[...nums], ans=[];
    arr.sort((a,b)=>a-b);
    let map={};
    map[arr[0]]=0;
    for(let i=1; i<arr.length; i++){
        if(arr[i-1]!==arr[i]) map[arr[i]]=i;
    }
    for(let i=0; i<nums.length; i++){
        ans.push(map[nums[i]]);
    }
    return ans;
};
How Many Numbers Are Smaller Than the Current Number