Trains the technique from
LeetCode 1922Count Good NumbersThis 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 warehouse prints shelf labels. A label is a row of exactly n digit slots, numbered from 0 on the left. The printer accepts a label only when
0, 2, 4, 6, 8, and2, 3, 5, 7.Leading zeros are ordinary digits here; a label is just a row of slots, not a number.
Given n, count the labels the printer accepts. The count grows far beyond what a 64-bit integer holds, so return it modulo 1000000007.
Example 1
Slots 0, 2, 4 and 6 each accept five digits and slots 1, 3 and 5 each accept four, so the printer accepts 625 * 64 = 40000 labels, which is already below the modulus.
Example 2
There are 13 even-numbered slots and 13 odd-numbered ones, and the resulting count reduced modulo 1000000007 is 426560007.
Example 3
The label has 450000000000000 slots of each kind, and the count reduced modulo 1000000007 is 676101114.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_good_numbers(n: int) -> int:public int countGoodNumbers(long n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.