How Many Numbers Are Smaller Than the Current Number
Real-world version: Bake Off Scores BeatenThe 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.
def strictly_below_counts(points: list[int]) -> list[int]:public int[] strictlyBelowCounts(int[] points)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 7 test cases: 7 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's