Skip to content
Katabench
Try free

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.

The hidden trap

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

C#
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.

C# coding challenges →

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