How Many Numbers Are Smaller Than the Current Number

Easy

Topics
ArrayHash TableCounting

For each nums[i], count how many nums[j] (j != i) are strictly smaller. Return the counts as an array.

Example 1

Input:  nums = [8,1,2,2,3]
Output: [4,0,1,1,3]

Example 2

Input:  nums = [6,5,4,8]
Output: [2,1,0,3]

Constraints

  • 2 <= nums.length <= 500
  • 0 <= nums[i] <= 100
Run ⌘' · Submit ⌘⏎