Grokking LinkedIn Coding Interview
Ask Author
Back to course home

0% completed

Isomorphic Strings (easy)
Table of Contents

Problem Statement

Examples

Try it yourself

Problem Statement

Given two strings s and t, return true if they are isomorphic. Otherwise, return false.

Two strings s and t are called isomorphic if the characters in string s can be replaced to get string t.

Each character in string t should be replaced with another character while preserving the order of characters as in string s. Two characters should not map to the same character, but a character may map to itself.

Examples

  • Example 1:

    • Input: s = "abb", t = "cdd"
    • Expected Output: true
    • Justification: Each character in "abb" can be replaced to match the corresponding character in "cdd" (a->c, b->d) while maintaining a one-to-one mapping.
  • Example 2:

    • Input: s = "cbcrt", t = "abaxv"
    • Expected Output: true
    • Justification: The characters in "cbcrt" can be replaced to form "abaxv" with a unique mapping for each character (c->a, b->b, r->x, t->v).
  • Example 3:

    • Input: s = "abcd", t = "bbcd"
    • Expected Output: false
    • Justification: The first string's characters cannot be replaced to form the string t while maintaining a unique mapping, as 'b' in the second string corresponds to both 'a' and 'b' in the s.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .
Mark as Completed

Table of Contents

Problem Statement

Examples

Try it yourself