How Many Numbers Are Smaller Than Current

EasyArrayMathSorting

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:

All elements are equal, so no value has a smaller number in the array. The exact output is [0,0,0,0].

Input:nums = [1,5,3,9,2]
Output:[0,3,2,4,1]
Explanation:

For 1 there are 0 smaller numbers; for 5 there are 3; for 3 there are 2; for 9 there are 4; and for 2 there is 1. So the exact output is [0,3,2,4,1].

Constraints

  • 2 ≤ nums.length ≤ 500

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!