Trains the technique from
LeetCode 474Ones and ZeroesThis 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 workshop marks parts with codes written only from the digits '0' and '1'. The list codes holds the codes waiting to be marked; the same code may appear more than once, and each entry in the list may be stamped at most once.
The tray holds zeros zero-stamps and ones one-stamps. Stamping a code consumes one stamp per digit of that code, of the matching kind, and every stamp is single use. A code counts only when all of its digits are stamped.
Return the largest number of entries from codes that can be stamped in full with the stamps in the tray.
Example 1
Stamping `"0"` uses the zero-stamp and stamping `"1"` uses the one-stamp, which finishes two entries. The tray is then empty.
Example 2
The only code needs two one-stamps and the tray holds one, so no entry can be finished.
Example 3
The four one-stamps cover `"1111"` exactly. `"0000"` needs four zero-stamps and only three are in the tray.
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 most_codes(codes: list[str], zeros: int, ones: int) -> int:public int mostCodes(String[] codes, int zeros, int ones)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.