Trains the technique from
LeetCode 916Word SubsetsThis 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.
Two lists of lowercase strings are given, labels and patterns, and no two labels are alike.
A label covers a pattern when, for every letter, the label holds that letter at least as many times as the pattern does.
Return the labels that cover every pattern in the list, in the order they appear in labels.
Example 1
Between them the patterns demand at least one `a`, one `c` and one `r`. Only the first label holds all three: the second has no `r` and the third no `c`.
Example 2
The pattern demands two `t`s, so holding a `t` is not enough. The first label has one and falls short; the second has two.
Example 3
The only label has no `b` at all, so nothing covers the pattern.
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 word_subsets(labels: list[str], patterns: list[str]) -> list[str]:public List<String> wordSubsets(String[] labels, String[] patterns)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.