Show problems as
Classic problem #1365EasyArrayHash TableSortingCounting Sort

How Many Numbers Are Smaller Than the Current Number

Real-world version: Bake Off Scores Beaten
Tracked in this browser only
Read How Many Numbers Are Smaller Than the Current Number on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A bake-off has finished and nums[i] is the panel score awarded to entry i, on a scale from 0 to 100.

The organisers want a card for every entry saying how many entries it beat outright. For entry i that is the number of positions j with j != i and nums[j] < nums[i]. Entries that tie on score beat each other zero times.

Return an array out of the same length as nums, where out[i] is the count for entry i, in the same order as the input.

Examples

Example 1

Input
nums = [7, 2, 7, 4]
Output
[2, 0, 2, 1]

Each 7 beats the 2 and the 4 but not the other 7, so both get 2; the 2 beats nothing; the 4 beats only the 2.

Example 2

Input
nums = [6, 6, 6, 6, 6]
Output
[0, 0, 0, 0, 0]

All five entries tie, so none of them beats another and every card reads 0.

Example 3

Input
nums = [0, 100]
Output
[0, 1]

The lowest score beats nothing and the highest beats the one entry below it.

Example 4

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

Each 9 sits above the 1, 5, 1 and 0, giving 4; each 1 sits above only the 0; the 5 sits above the two 1s and the 0.

Constraints

  • 2 <= nums.length <= 500
  • 0 <= nums[i] <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def strictly_below_counts(points: list[int]) -> list[int]:
Java
public int[] strictlyBelowCounts(int[] points)