All Long Subsequences Are Dictionary Words
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's February 2026 OA has a question that looks like a subsequence explosion but hinges on a hash set. You get a string up to 18 characters and a dictionary up to 200000 words, and you have to say whether every subsequence of length 3 or more is a real word, and whether each one at least has an anagram in the dictionary. The trick is that 2^18 is tiny. If you blank on the structure, StealthCoder is the invisible safety net running during the live OA, but the approach is simple enough to hold in your head.
The problem
Given a lowercase string text and a finite lowercase dictionary, consider every subsequence of text whose length is at least 3. A subsequence keeps relative order and is identified by its resulting string; repeated ways to form the same string do not change the decision. Return two booleans: answer[0] is true exactly when every considered subsequence appears in the dictionary. answer[1] is true exactly when, for every considered subsequence, at least one dictionary word is an anagram of it. If text.length < 3, both statements are vacuously true. Duplicate dictionary entries have no effect. Function allSubsequencesAreWords(text: String, dictionary: String[]) → boolean[] Examples Example 1 text = "abc" dictionary = ["abc","cab"] return = [true,true] The only qualifying subsequence is abc. It is present directly and also has dictionary anagrams. Example 2 text = "abc" dictionary = ["bca"] return = [false,true] The subsequence abc is not itself in the dictionary, but bca is an anagram of it. Example 3 text = "abcd" dictionary = ["abc","abd","acd","bcd","abcd"] return = [true,true] The four length-three subsequences and the full length-four subsequence all appear directly, so both conditions hold. Constraints 0 <= text.length <= 18 0 <= dictionary.length <= 200000 text and every dictionary word contain only lowercase English letters. Each dictionary word has length at most 18. The total number of dictionary characters is at most 1000000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Enumerate every bitmask of text, up to 262144 of them. Skip masks with fewer than 3 bits. Build the subsequence string, then dedupe with a set so repeated strings count once. Put all dictionary words in a hash set for part one. For part two, build a second hash set of sorted-letter keys (or 26-count signatures) from every dictionary word. Then for each unique subsequence, check membership in the word set and check its sorted key in the anagram set. Both answers are just AND across all subsequences. The common pitfall is looping over the dictionary per subsequence, which is far too slow. Another is forgetting the vacuous case when length is under 3, where you return [true,true]. Sorting 18 characters per subsequence is cheap enough. StealthCoder is the hedge if you freeze on the anagram key idea during the live OA.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill All Long Subsequences Are Dictionary Words cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
All Long Subsequences Are Dictionary Words FAQ
What's the trick in All Long Subsequences Are Dictionary Words?+
Use hash sets. Store dictionary words in one set and their sorted-letter signatures in another. Then enumerate all bitmask subsequences of the text, which is at most 2^18, and do O(1) lookups for each. Never scan the dictionary per subsequence.
How hard is this one really?+
Easier than it looks. The constraint of 18 characters signals brute-force bitmask enumeration is intended. The only real thinking is the anagram check, which sorted keys or count signatures solve cleanly.
Do duplicate subsequences matter?+
No. The problem says a subsequence is identified by its string, so repeated ways to form it don't change the result. Since you're only checking membership, duplicates won't flip an answer, but a set of seen strings saves repeated work.
What should I return for short text?+
If text length is under 3, no subsequence qualifies, so both statements are vacuously true. Return [true,true] immediately. This is an easy edge case to miss when the loop simply never runs and you've initialized flags wrongly.
How do I prepare for this in 48 hours?+
Practice generating subsequences with bitmasks, building canonical anagram keys, and using hash sets for lookups. Write the solution once end to end. Watch the edge cases: empty text, empty dictionary, and duplicate dictionary words, which have no effect.