All problems
0769EasyArrayString

Labels Carrying A Given Letter

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2942Find Words Containing Character

This 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.

Examples

Example 1

Input
labels = ["mango", "plum", "fig"], mark = "m"
Output
[0, 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

Input
labels = ["pear", "plumb", "kale"], mark = "b"
Output
[1]

Only "plumb" carries a "b", and it is the last character of that label, so position 1 is the single answer.

Example 3

Input
labels = ["fig", "kiwi"], mark = "q"
Output
[]

Neither label contains a "q", so the answer is empty.

Constraints

  • 1 <= labels.length <= 50
  • 1 <= labels[i].length <= 50
  • mark is a lowercase English letter.
  • labels[i] consists only of lowercase English letters.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def labels_with_letter(labels: list[str], mark: str) -> list[int]:
Java
public List<Integer> labelsWithLetter(String[] labels, char mark)
September 7
Apply