27. Isomorphic Strings
easyAsked at PlaidDetermine if two strings are isomorphic — one character maps to one other character consistently. Plaid asks this because tokenizing merchant strings under a consistent mapping is the same primitive.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Plaid loops.
- LeetCode Discuss (2026)— Plaid OA — frame as merchant token mapping.
- Glassdoor (2025)— Plaid intro.
Problem
Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
Constraints
1 <= s.length <= 5 * 10^4t.length == s.lengths and t consist of any valid ASCII character.
Examples
Example 1
s = "egg", t = "add"trueExample 2
s = "foo", t = "bar"falseExample 3
s = "paper", t = "title"trueApproaches
1. One-way mapping
Map each s[i] to t[i]. Fail if a conflicting mapping appears.
- Time
- O(n)
- Space
- O(1) for ASCII
function isIsomorphic(s, t) {
const m = new Map();
for (let i = 0; i < s.length; i++) {
if (m.has(s[i])) {
if (m.get(s[i]) !== t[i]) return false;
} else m.set(s[i], t[i]);
}
return true;
}Tradeoff: Misses the 'no two chars map to the same target' rule. Fails on s="ab", t="aa".
2. Bidirectional mapping
Track s->t AND t->s. Both must be consistent.
- Time
- O(n)
- Space
- O(1) for ASCII
function isIsomorphic(s, t) {
const st = new Map(), ts = new Map();
for (let i = 0; i < s.length; i++) {
if (st.has(s[i]) && st.get(s[i]) !== t[i]) return false;
if (ts.has(t[i]) && ts.get(t[i]) !== s[i]) return false;
st.set(s[i], t[i]);
ts.set(t[i], s[i]);
}
return true;
}Tradeoff: Bijective mapping ensured. The 'two maps in parallel' is the standard pattern for one-to-one matching.
Plaid-specific tips
Plaid grades this on whether you spot the bijection requirement. Bonus signal: name it 'bijective' aloud. Connect it to merchant-tokenization — where 'STARBUCKS #234' and 'STARBUCKS #567' must reduce to the same canonical token, but two different merchants must never collapse to the same token.
Common mistakes
- One-way mapping only — misses 'two source chars to one target' bug.
- Using a single map keyed by 'char-pair' string — wasteful allocation.
- Comparing lengths first then iterating — fine but the problem guarantees equal length.
Follow-up questions
An interviewer at Plaid may pivot to one of these next:
- Word pattern (LC 290) — same idea, words instead of chars.
- Anagram check across multiple strings.
- Group anagrams (LC 49).
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why bidirectional?
The rule says no two source chars map to the same target. Tracking only s->t doesn't catch that case.
Why two maps instead of one combined?
Two maps make the bijection invariant readable. A combined char-pair key works but is harder to reason about.
Practice these live with InterviewChamp.AI
Drill Isomorphic Strings and other Plaid interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →