Trains the technique from
LeetCode 902Numbers At Most N Given Digit SetThis 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 hand press builds a label by pressing digit stamps left to right, and the finished label is read as an ordinary decimal number. The tray holds the stamps listed in stamps, each a one-character string. A stamp can be pressed as many times as you like, and a label may be any length from one stamp upwards.
Return how many different positive integers no greater than limit can be produced this way. Two labels that read as the same number count once. Since no stamp carries the digit 0, a number needing a 0 anywhere cannot be pressed at all.
Example 1
The one-stamp labels 2, 4 and 7 all fit, and so do the nine two-stamp labels from 22 up to 77. Of the three-stamp labels only 222, 224, 227, 242, 244, 247, 272, 274 and 277 come out at 386 or below, giving twenty-one labels in all.
Example 2
The printable values at 15 or below are 1, 5, 11 and 15. The remaining two-stamp labels, 51 and 55, are both over the limit.
Example 3
The shortest label the tray can press reads 5, which is already above the limit, so no value qualifies.
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 printable_labels(stamps: list[str], limit: int) -> int:public int printableLabels(String[] stamps, int limit)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.