Description
Given the array nums, for each nums[i] count how many numbers in the array are smaller than it. Return the counts as an array in the same order.
Examples
Input:
nums = [8,1,2,2,3]Output:
[4,0,1,1,3]Explanation:
Count smaller for each.
Input:
nums = [7,7,7,7]Output:
[0,0,0,0]Explanation:
When all elements are equal, no element is smaller than any other element, so the count is 0 for each position.
Input:
nums = [1,5,3,9,2]Output:
[0,3,1,4,1]Explanation:
For 1: no elements smaller (0). For 5: elements 1,3,2 are smaller (3). For 3: element 1,2 are smaller (1). For 9: all other elements 1,5,3,2 are smaller (4). For 2: element 1 is smaller (1).
Constraints
- •
2 ≤ nums.length ≤ 500