All problems
0328EasyArrayHash TableSortingCounting Sort

Bake Off Scores Beaten

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1365How Many Numbers Are Smaller Than the Current Number

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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