Isomorphic Strings
Easy About 10 min Free, no account needed
Can one string be turned into the other by a consistent character substitution?
The brief
Two strings s and t are isomorphic when the characters of s can be
replaced to obtain t:
- every occurrence of a character must map to the same character,
- no two characters may map to the same character (the substitution must be reversible),
- a character may map to itself.
Return true when s and t are isomorphic.
A mapping checked in only one direction accepts pairs like "ab" / "aa"
(both a and b map onto a, not reversible). The hidden tests probe exactly
these cases, so make the mapping consistent both ways.
Starter code
using System;
using System.Collections.Generic;
public class Solution
{
// TODO: return true when a consistent character substitution turns s into t.
public bool AreIsomorphic(string s, string t)
{
throw new NotImplementedException();
}
}How it is graded
Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.
What it practices
- Hash maps and sets
- Trade memory for constant-time lookups, membership tests and frequency counts.
- String processing
- Parse, scan and match text character by character with correct edge cases.
Related katas
- Count Distinct Letters Easy Free How many different letters appear? A 26-slot array already knows.
- Add Binary Strings Easy Free Add two binary numbers far too long for any built-in integer.
- Maximum Bracket Depth Easy Free How deep do the parentheses nest? A counter beats a stack.
- Base64 Decoded Length Easy Free The decoded size is pure arithmetic - no need to decode.