Skip to content

2942. Find Words Containing Character #1721

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the indices of words in a given list that contain a specific character. The solution involves iterating through each word and checking if the character is present, then collecting the indices of those words.

Approach

  1. Initialize an empty array to store the indices of words that contain the specified character.
  2. Iterate through each word in the input list while keeping track of the current index.
  3. Check if the character exists in the current word using the strpos function. If the character is found, add the current index to the result array.
  4. Return the result array after processing all words.

This approach efficiently checks each word for the presence of the character using …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit May 24, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim May 24, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants