Count, for each number in an array, how many values are strictly smaller than it.
Given an integer array nums, return a new array answer such that answer[i] is the number of elements in nums that are strictly smaller than nums[i].
You must compute this for every position independently.
nums.nums.answer where each entry contains the count of values in nums that are smaller than the corresponding value.1 <= nums.length <= 5000 <= nums[i] <= 100nums.answer of the same length as nums.1 <= nums.length <= 5000 <= nums[i] <= 100Example 1
Input
nums = [8,1,2,2,3]
Output
[4,0,1,1,3]
Explanation
Example 2
Input
nums = [6,5,4,8]
Output
[2,1,0,3]
Explanation
Example 3
Input
nums = [7,7,7,7]
Output
[0,0,0,0]
Explanation
All values are equal, so none of them has a strictly smaller value in the array.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.