Count Element Symbol Decompositions
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Brute force dies here the moment the word gets long, because every position can branch into a one-letter or two-letter symbol and the splits multiply fast. Google reported this one in July 2026: count how many ways a word breaks into a sequence of element symbols, case-insensitive. It's a word-break counting problem in disguise, and the pattern is dynamic programming over prefixes. If you spot that in the first minute, the rest is bookkeeping. If you blank, StealthCoder runs invisibly during the live OA as a safety net and hands you the structure.
The problem
Given a collection of chemical element symbols symbols and a word word, return the number of ways to split the entire word into a sequence of the supplied symbols. Symbol matching is case-insensitive. Function countElementSymbolDecompositions(symbols: String[], word: String) → int Examples Example 1 symbols = ["P", "H", "Y", "S", "I", "C", "Si", "Cs"] word = "Physics" return = 4 The four decompositions are P-H-Y-Si-C-S, P-H-Y-Si-Cs, P-H-Y-S-I-C-S, and P-H-Y-S-I-Cs.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Define dp[i] as the number of ways to split the first i characters. dp[0] = 1. For each i, look back at every symbol length that exists in your set (usually 1 or 2, but don't hardcode it, loop over the actual lengths). If word[i-len..i] lowercased is in the set, add dp[i-len] to dp[i]. The answer is dp[n]. Lowercase both the symbols and the word up front, and store symbols in a hash set. The common pitfall is plain recursion without memoization, which blows up exponentially. Another trap is counting duplicate symbols twice if the input repeats them, so dedupe through the set. Check the example: Physics gives 4 because Si/S+I and Cs/C+S each branch independently. Use a 64-bit integer if counts could grow large. If the recurrence slips away mid-assessment, StealthCoder is the hedge that gives you the working solution in real time.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Count Element Symbol Decompositions 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Element Symbol Decompositions FAQ
What's the trick to Count Element Symbol Decompositions?+
Treat it as word break with counting. dp[i] is the number of ways to split the first i characters, and you sum dp[i-len] whenever the substring ending at i is a valid symbol. Lowercase everything first so matching is case-insensitive.
How hard is this one really?+
Medium. If you've seen word break, it's quick. The only twist is that you count ways instead of returning true or false, so you add instead of OR. The recurrence is about five lines once you see it.
Why does brute force fail?+
Each position can branch into multiple symbol lengths, so plain recursion revisits the same suffixes over and over and grows exponentially. Memoizing on index or building a bottom-up dp array makes it linear in word length times the number of distinct symbol lengths.
How do I handle case-insensitivity?+
Lowercase every symbol when you build the hash set, and lowercase the word once before the dp loop. Then compare substrings directly. Don't lowercase inside the inner loop, it's wasted work and easy to forget on one side.
How do I prepare for this in 48 hours?+
Write word break and word break II from scratch, then change the return to a count. Practice the dp[0] = 1 base case and a hash set lookup of substrings. That covers the pattern Google reported in July 2026.