DSA interview question
A cipher checker receives a plaintext s and a ciphertext t and must decide whether t could come from s by a consistent one-to-one letter substitution: every occurrence of a letter maps to the same replacement, and no two different letters share a replacement. For example "egg" → "add" works (e→a, g→d), but "foo" → "bar" doesn't (o can't map to both a and r). The mapping has to be checked in both directions; forgetting the reverse direction is the classic bug.
Example: ("paper", "title") → true; ("badc", "baba") → false.
bool isIsomorphic(const string& s, const string& t);
Input (s, t) | Output | Explanation |
|---|---|---|
("egg", "add") | true | e→a, g→d |
("foo", "bar") | false | o would map to both a and r |
("paper", "title") | true | p→t, a→i, e→l, r→e |
("badc", "baba") | false | b→b and d→b: two letters share a target |
("a", "a") | true | |
("ab", "aa") | false | The reverse direction fails |
(Confirm: s and t have the same length; characters are ASCII; a character may map to itself.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in