Ctrl K

Words With the Letter

Easy
You are given an array of words words and a letter letter. Return the zero-based indices of every word that contains letter at least once. The indices may be returned in any order.
Example 1
words=['river', 'stone', 'cloud', 'rain'], letter='r' → [0, 3]

The letter "r" occurs in "river" and "rain", at indices 0 and 3.

Example 2
words=['moon', 'sun'], letter='k' → []

No word contains "k", so the answer is empty.

Constraints
  • 1 ≤ words.length ≤ 50
  • 1 ≤ words[i].length ≤ 50
  • letter is a lowercase English letter
  • words[i] consists only of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Words, Closest Apart EasyOne-Row Typing EasyDinner for Two EasyPhrases with Synonyms EasyWord from a License Plate Easy
loading Python…
Input
words=['river', 'stone', 'cloud', 'rain'], letter='r'
Expected
[0, 3]

Run checks the first 3 tests in your browser. Submit checks all 141 tests on the server, hidden ones included.