Trains the technique from
LeetCode 392Is SubsequenceThis 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.
An archivist writes a short code on a box and a longer label on the shelf card it belongs to. Both are made of lowercase English letters.
The code fits the label when every letter of the code can be matched to a position of the label so that the matched positions increase from the first letter of the code to the last, and no position of the label is used twice. Matched positions do not have to sit next to each other, and letters of the label may be left unmatched.
Return true when the code fits the label and false when it does not. A code with no letters fits every label.
Example 1
Matching `f` to position 0, `i` to position 2 and `g` to position 3 uses increasing positions of the label for the three letters in order.
Example 2
The label carries `g` only at position 3, and it holds no `i` or `f` after that position, so the letters cannot be matched in the order the code gives them.
Example 3
The label holds one `t` and a position cannot be used twice, so the second `t` of the code has nothing left to match.
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 code_fits_label(code: str, label: str) -> bool:public boolean codeFitsLabel(String code, String label)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.