Trains the technique from
LeetCode 2942Find Words Containing CharacterThis 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 shelf holds product labels in the order given by labels, where labels[i] is the text printed on the label at position i. You are also given mark, a single lowercase letter.
Find every position whose label has mark somewhere in its text, anywhere at all, not just at the start or the end. A label carrying mark several times still counts as one position.
Return those positions in increasing order. When no label carries mark, return an empty list.
Example 1
"mango" opens with the letter and "plum" carries it as its third character, so positions 0 and 1 qualify. "fig" has no "m".
Example 2
Only "plumb" carries a "b", and it is the last character of that label, so position 1 is the single answer.
Example 3
Neither label contains a "q", so the answer is empty.
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 labels_with_letter(labels: list[str], mark: str) -> list[int]:public List<Integer> labelsWithLetter(String[] labels, char mark)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.