InterviewBit Academy is now Scaler!
InterviewBit Academy is now Scaler Academy!

Count of smaller numbers after self

Given an array of integers A,
find and return new integer array B.
B array has the property where B[i] is the number of smaller elements to the right of A[i].

Input Format

The only argument given is the integer array A.

Output Format

Return the new integer array B.


1 <= length of the array <= 100000
1 <= A[i] <= 10^9 

For Example

Input 1:
    A = [1, 5, 4, 2, 1]
Output 1:
    B = [0, 3, 2, 1, 0]

Input 2:
    A = [5, 17, 100, 11]
Output 2:
    B = [0, 1, 1, 0]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Count of smaller numbers after self on Interview Code Editor
Sign Up
to access hints and editorial solutions for Count of smaller numbers after self


Click here to start solving coding interview questions