Apply Substitutions
A medium-tier problem at 79% community acceptance, tagged with Array, Hash Table, String. Reported in interviews at Google and 0 others.
Apply Substitutions is a medium-difficulty problem that surfaces in Google's OAs. The acceptance rate hovers around 79%, which tells you most candidates who see it pass, but that's because they either know the graph/substitution pattern or they don't. You're either seeing it fresh on assessment day and winging it, or you recognize the trick. The problem layers string transformation with cycle detection. If you hit this cold during your live OA and the obvious greedy approach falls apart, StealthCoder solves it invisibly in seconds.
Companies that ask "Apply Substitutions"
Apply Substitutions is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThis problem hinges on recognizing that substitution chains can form cycles, and you need to detect them or apply transformations in the right order. The naive approach (apply each substitution sequentially) fails when substitutions reference characters that get substituted later, or when circular dependencies exist. The real solution models substitutions as a directed graph and uses either DFS for cycle detection or topological sort to determine application order. Hash tables store the substitution map, and you traverse either depth-first or breadth-first depending on your chosen strategy. The trap is not realizing that order matters and cycles break greedy logic. When you're live in the assessment and you've burned 10 minutes on a wrong approach, StealthCoder surfaces the correct graph-based solution immediately.
Pattern tags
You know the problem.
Make sure you actually pass it.
Apply Substitutions recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Apply Substitutions interview FAQ
Is this problem actually hard or does the 79% acceptance rate mean it's easier than it looks?+
The high acceptance rate reflects that the pattern is learnable, not that the problem is trivial. Most candidates who pass have either seen substitution/graph problems before or they've drilled cycle detection. Cold solves are much messier. The rate hides the fact that interview time pressure kills greedy approaches fast.
Why does the greedy approach of just applying substitutions in order fail?+
Because a substitution might reference a character that itself gets substituted. If you apply substitutions left-to-right without considering dependencies, you either miss updates or create incorrect chains. The problem forces you to think about dependency order, not just sequential application.
What's the connection between DFS and topological sort in this problem?+
DFS detects cycles in the substitution graph and orders valid transformations. Topological sort explicitly determines the correct application sequence when no cycles exist. Both are graph traversal patterns. The input topics list both, which signals you need to think about the underlying DAG structure, not just string iteration.
Should I use a hash table or something else to store substitutions?+
Hash table is the standard choice for fast O(1) lookup of substitution rules. Combined with a graph representation of dependencies, it lets you iterate and build the transformation chain efficiently. Array context here is usually the input or result, not the substitution map itself.
Google asks this. How often does it actually show up in their OAs?+
Google appears as the only reported company in this problem's data, suggesting it's part of their interview rotation but not necessarily high frequency. It's the kind of problem that tests whether you can spot a graph pattern hiding in a string transformation prompt.
Want the actual problem statement? View "Apply Substitutions" on LeetCode →