easyHashingPattern: Hash Map / Bijection

Isomorphic String Mapping Solution

Problem Statement

Given two strings `s` and `t`, determine if there exists a one-to-one mapping between the characters of `s` and `t`. The mapping is valid if every character in `s` maps to a unique character in `t` and vice versa.

Examples

Example 1:
Input:{"s":"egg","t":"add"}
Output:true
Example 2:
Input:{"s":"foo","t":"bar"}
Output:false

Constraints

  • 1 <= s.length <= 5 * 10^4
  • t.length == s.length
Time: O(N) Space: O(1)
Use two arrays of size 256 for mapping s->t and t->s. If mismatch found, return false. Time O(N), Space O(1).

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.