Trains the technique from
LeetCode 10Regular Expression MatchingThis 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 parts catalogue lets a technician look up stock with a mask instead of an exact serial. You are given a serial code of lowercase letters and a mask mask, and you have to decide whether the mask describes that serial.
Read mask left to right as a run of items. An item is one lowercase letter, which stands for that letter alone, or '.', which stands for any one letter. Writing '*' straight after an item says that the item is used some number of times over, possibly not at all. Every '*' in mask is guaranteed to follow an item.
Return true when the items account for code from its first letter through its last, with nothing left over on either side, and false otherwise. Covering a leading chunk of code is not enough.
Example 1
The item z is used zero times over, so the mask boils down to h, a, r, p, which lines up with the serial.
Example 2
Each dot stands in for one letter, so the four items cover all four letters of the serial.
Example 3
The items only reach the first three letters and nothing accounts for the trailing p.
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 mask_matches(code: str, mask: str) -> bool:public boolean maskMatches(String code, String mask)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.