Check if all substrings are dictionary words
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates string-processing skills such as substring enumeration and membership testing against a dictionary, along with algorithmic reasoning about correctness and complexity.
Part 1: Check Whether Every Subsequence of Length >= 3 Is a Dictionary Word
Constraints
- 0 <= len(s) <= 18
- 0 <= len(dictionary) <= 3000
- 1 <= len(word) <= 18 for each word in dictionary
- s and all dictionary words contain only lowercase English letters
Examples
Input: ('cat', ['cat'])
Expected Output: True
Explanation: The only subsequence of length >= 3 is 'cat', which is in the dictionary.
Input: ('cats', ['cat', 'cas', 'cts', 'ats', 'cats'])
Expected Output: True
Explanation: All distinct subsequences of length >= 3 are: 'cat', 'cas', 'cts', 'ats', and 'cats'. All are present.
Input: ('cats', ['cat', 'cts', 'ats', 'cats'])
Expected Output: False
Explanation: The subsequence 'cas' is missing from the dictionary.
Input: ('', [])
Expected Output: True
Explanation: There are no subsequences of length >= 3, so the condition is vacuously true.
Input: ('aaaa', ['aaa', 'aaaa'])