# Problem Statement :

Sample Input:

`N = 5arr = [5 4 3 2 -1]`

Sample Output:

`4 3 2 1 0`

# Explanation of given Test Cases :

`Number of elements smaller than 5 on its right side {4,3,2,-1} which is 4Number of elements smaller than 4 on its right side {3,2,-1} which is 3Number of elements smaller than 3 on its right side {2,-1} which is 2Number of elements smaller than 2 on its right side {-1} which is 1Thus answer is [4,3,2,1,0]`

# Approach :

Algorithm :

• Create a list ‘arr1’ such that ‘arr1[i]’ stores [arr[i],i].Create an ‘ans’ list of size of ’n’ with default value 0.
• Create a recursive function that divides the list ‘arr1’ into two sorted list by the value.
• Create a function merge similar to merge sort one that will merge two sorted list into one.
• In the merge function create two indices i and j, i is the index for the first half, and j is an index of the second half.Create a variable count with a value of 0.if arr1[i] greater than arr1[j] then do temp++.Else do ans[arr1[i] += temp.(Adding the values which are less than arr1[i] corresponding to its index) and then do i++.
• After this run a loop until i<mid and do ans[arr[i]]+=temp(To update the values for remaining elements.
• In the end, return ans list.

Time Complexity: O(n*log(n))
Space Complexity: O(n)