532. Count of Smaller Numbers After Self

HardBinary SearchBinary SearchMerge SortBIT

Given an array, return an array where the i-th value is the number of elements to the right of index i that are strictly smaller than the element at i. Input: an array of integers.

Input: An array of integers.

Output: Array — counts of smaller elements after each index.

Examples

Example 1
Input: [5,2,6,1]
Output: [2,1,1,0]
Explanation: 5 has 2 smaller to its right, etc.
Example 2
Input: [-1,-1]
Output: [0,0]
Explanation: No strictly smaller elements.
Example 3
Input: [2,0,1]
Output: [2,0,0]
Explanation: 2 dominates both.

Constraints

Asked by

GoogleInfosysBloombergMicrosoftAmazonMeta
Solve this problem in the editor →