Description
Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. Return the result as an array.
Examples
Input:
nums = [8,1,2,2,3]Output:
[4,0,1,1,3]Explanation:
Count smaller elements.
Input:
nums = [3, 5, 2, 5, 1]Output:
[2, 3, 1, 3, 0]Explanation:
For 3: numbers 2 and 1 are smaller (count=2). For 5: numbers 3, 2, and 1 are smaller (count=3). For 2: only 1 is smaller (count=1). For the second 5: same as first 5, count=3. For 1: no numbers are smaller (count=0).
Input:
nums = [10, 9]Output:
[1, 0]Explanation:
This tests the minimum array length constraint. For 10: only 9 is smaller (count=1). For 9: no numbers are smaller than 9 (count=0). This demonstrates the simplest possible case with just 2 elements.
Constraints
- •
2 ≤ nums.length ≤ 500