Isomorphic Strings
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that kills a naive Isomorphic Strings solution is the reverse mapping. Microsoft reportedly served this one in September 2025, and plenty of people will check s to t consistency and call it done. That passes "paper" and "title" and "foo" and "bar", then fails "badc" and "baba". It's a hash-table problem at heart, two maps or one map plus a seen set, and it runs in linear time. If you blank on the second rule mid-assessment, StealthCoder runs invisibly on your desktop as a safety net and hands you the bijection check in real time.
The problem
Given two strings s and t of equal length, determine whether their characters have a bijective mapping. A valid mapping must satisfy both rules: Every occurrence of one character in s maps to the same character in t. Two different characters in s cannot map to the same character in t. Character positions do not change, and a character may map to itself. Function isIsomorphic(s: String, t: String) → boolean Examples Example 1 s = "paper" t = "title" return = true The repeated-character pattern matches: p maps to t, a to i, e to l, and r to e. Example 2 s = "foo" t = "bar" return = false The two occurrences of o would need to map to both a and r, which is inconsistent. Example 3 s = "badc" t = "baba" return = false Although each character from s is individually consistent, both b and d would map to b, violating bijection. Constraints 1 <= s.length == t.length <= 50000 s and t contain ASCII characters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that a mapping has to hold in both directions. Walk both strings together. Keep a map from s characters to t characters and a second map from t characters back to s. At each index, if s[i] already maps to something other than t[i], return false. If t[i] is already claimed by a different s character, return false. Otherwise record both. That's O(n) time and O(1) space, since the alphabet is ASCII. The common pitfall is checking only the forward map, which wrongly accepts "badc" and "baba" because b and d both land on b. Another slip is comparing character counts, which ignores position. A neat alternative is to compare first-occurrence indexes for each position. If you freeze during the live OA, StealthCoder is the hedge that reads the problem on screen and gives you the two-map version without anyone seeing it.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Isomorphic Strings 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as isomorphic strings. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Microsoft's OA.
Microsoft reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Isomorphic Strings FAQ
How hard is Isomorphic Strings really?+
It's easy on paper. The code is ten lines. The only real difficulty is remembering the mapping must be one-to-one, so you need a check in both directions. Most failed attempts come from handling only s to t and missing the collision case like badc and baba.
What's the trick to solve it fast?+
Use two hash maps, one for s to t and one for t to s. At each index, verify both existing mappings agree with the current pair. If either disagrees, return false. One pass, linear time. Don't overthink it or sort anything.
Can I use one map instead of two?+
Yes. Keep one map from s to t and a set of t characters already used. When you meet a new s character, make sure its target isn't in the used set. This enforces the bijection with the same linear time and constant extra space.
Why does badc and baba return false?+
Every character in s maps consistently on its own. But b maps to b and d also maps to b, so two different source characters share one target. That breaks the bijection rule. A forward-only check misses this, which is why the reverse map matters.
How do I prepare for this in 48 hours?+
Write the two-map solution from memory twice. Then test it on paper and title, foo and bar, and badc and baba. Add a case where s equals t and a single-character case. With n up to 50000, linear time is fine. That's the whole prep.