You are given a 0-indexed array of strings words and a character x.
Return an array of indices representing the words that contain the character x.
Note that the returned array may be in any order.
1 <= words.length <= 501 <= words[i].length <= 50x is a lowercase English letterwords[i] consists only of lowercase English lettersIterate through each word and check if it contains the target character x.
Algorithm:
xi in the words array:
    x, add i to result list and breakx multiple timesThis approach works because:
Example 1: words = ["leet","code"], x = 'e'
Step-by-step execution:
Result: [0, 1]
Example 2: words = ["abc","bcd"], x = 'x'
Step-by-step execution:
Result: [] (empty array)
Example 3: words = ["leet","leet"], x = 'e'
Step-by-step execution:
Result: [0, 1] (duplicate indices allowed if same word appears twice)
class Solution {
    public List<Integer> findWordsContaining(String[] words, char x) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            for (char ch : words[i].toCharArray()) {
                if (ch == x) {
                    list.add(i);
                    break;
                }
            }
        }
        return list;
    }
}
class Solution {
    public List<Integer> findWordsContaining(String[] words, char x) {
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            if (words[i].contains(String.valueOf(x))) {
                result.add(i);
            }
        }
        return result;
    }
}
Explanation: Use Java’s built-in contains() method instead of manual character checking.
Time Complexity: O(N × L) - contains() method still checks each character Space Complexity: O(1) - excluding output list
class Solution {
    public List<Integer> findWordsContaining(String[] words, char x) {
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            if (words[i].chars().anyMatch(ch -> ch == x)) {
                result.add(i);
            }
        }
        return result;
    }
}
Explanation: Use Java streams with anyMatch() to check if any character matches.
Time Complexity: O(N × L) - stream operations Space Complexity: O(1) - excluding output list
class Solution {
    public List<Integer> findWordsContaining(String[] words, char x) {
        List<Integer> result = new ArrayList<>();
        for (int i = 0; i < words.length; i++) {
            if (words[i].indexOf(x) != -1) {
                result.add(i);
            }
        }
        return result;
    }
}
Explanation: Use indexOf() method which returns -1 if character not found.
Time Complexity: O(N × L) - indexOf() searches through string Space Complexity: O(1) - excluding output list
class Solution {
    public List<Integer> findWordsContaining(String[] words, char x) {
        return IntStream.range(0, words.length)
                       .parallel()
                       .filter(i -> words[i].contains(String.valueOf(x)))
                       .boxed()
                       .collect(Collectors.toList());
    }
}
Explanation: Use parallel streams for better performance on large datasets.
Time Complexity: O(N × L) - with potential parallel speedup Space Complexity: O(1) - excluding output list