115. Count of Smaller Numbers After Self

HardArrayArray

Given an integer array nums, return an integer array counts where counts[i] is the number of elements to the right of nums[i] that are smaller than nums[i].

Input: Integer array nums.

Output: Integer array where counts[i] = number of smaller elements to the right of nums[i].

Examples

Example 1
Input: [5,2,6,1]
Output: [2,1,1,0]
Explanation: 5: [2,1]→2. 2: [1]→1. 6: [1]→1. 1: []→0.
Example 2
Input: [2,0,1]
Output: [2,0,0]
Explanation: 2: [0,1]→2. 0: []→0. 1: []→0.
Example 3
Input: [1,2,3,4,5]
Output: [0,0,0,0,0]
Explanation: No smaller elements to the right.

Constraints

Asked by

GoogleInfosysBloombergMicrosoftAmazonMeta
Solve this problem in the editor →