Back to problems Sign in to unlock
Leetcode
Easy
Arrays
Strings
Find Words Containing Character
Return all words that contain a given character at least once.
Acceptance 100%
Problem Statement
Problem
You are given an array of lowercase words and a single character x.
Return the indices of all words that contain x at least once, in the same order as the input.
A word is selected if any character in the word matches x exactly.
Input Format
words: an array of stringsx: a character
Output Format
- Return an array of indices of the words that contain
x.
Constraints
1 <= words.length <= 1001 <= words[i].length <= 100xis a single lowercase English letter- All words contain only lowercase English letters
Notes
The task is a straightforward scan through each string and keep the positions of matching words.
Input Format
words: array of lowercase stringsx: single lowercase character
Output Format
- array of integer indices in increasing order
Constraints
1 <= words.length <= 1001 <= words[i].length <= 100xis one lowercase English letter- words contain only lowercase English letters
Examples
Sample cases returned by the problem API.
Example 1
Input
words = ["leet","code"], x = "e"
Output
[0,1]
Explanation
Both "leet" and "code" contain the character 'e'.
Example 2
Input
words = ["abc","bcd","aaaa","cbc"], x = "a"
Output
[0,2]
Explanation
Only "abc" and "aaaa" contain 'a'.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.