AlgoMaster Logo

Isomorphic Strings

Last Updated: November 21, 2025

Ashish

Ashish Pratap Singh

Problem Description

Solve it on LeetCode

Approaches

1. Hash Maps

Intuition:

To better understand the character relationships, we'll use two hash maps. This solution tracks mapping from both s to t and t to s, ensuring a one-to-one and onto mapping.

  • Create two hash maps.
  • For each character, ensure the mapping is unique and consistent in both directions.

Code:

2. Frequency Array

Intuition:

Since s and t are ascii characters, we can use frequency arrays of size 256 instead of using an explicit hash map (which comes with overhead).

  • For each character in the given strings, map them into a fixed-size array based on ASCII values.
  • Check if there is a consistent mapping from characters of s to t and t to s.

Code: