Ctrl K

Words From Working Keys

Easy
On an old keyboard only some keys still work; their letters are listed in the string keys (all distinct). You also get a list of words words. A word can be typed if every one of its letters is on a working key. A key may be pressed as many times as you like. Return how many words in words can be typed on this keyboard.
Example 1
keys="tea", words=["tea", "eat", "tear", "ate", "seat"] → 3

You can type "tea", "eat" and "ate". "tear" needs r and "seat" needs s, and neither key works.

Example 2
keys="no", words=["no", "on", "noon", "onion"] → 3

A key can be pressed any number of times, so "noon" works. "onion" has an i, so it does not.

Example 3
keys="z", words=["a", "b"] → 0
Constraints
  • 1 ≤ len(keys) ≤ 26, all characters of keys are distinct
  • 1 ≤ len(words) ≤ 10⁴
  • 1 ≤ len(words[i]) ≤ 10
  • keys and words[i] consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPairs With the Same Letter Set EasyWords From Letter Tiles EasyThe k-th Word With No Repeats EasyWords Listed Once in Both EasyMatching Sock Pairs Easy
loading Python…
Input
keys="tea", words=["tea", "eat", "tear", "ate", "seat"]
Expected
3

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