1786. Count the Number of Consistent Strings
My accepted JavaScript solution to LeetCode problem 1786, Count the Number of Consistent Strings, running in 60ms.
- Difficulty: Easy
- JavaScript
- Runtime 60ms
- Memory 63.7MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 60ms, memory 63.7MB, accepted 2025-12-29.
/**
* @param {string} allowed
* @param {string[]} words
* @return {number}
*/
var countConsistentStrings = function(allowed, words) {
const set = new Set(allowed);
let count = 0;
for (const word of words) {
let valid = true;
for (const c of word) {
if (!set.has(c)) {
valid = false;
break;
}
}
if (valid) count++;
}
return count;
};