Two strings s and t are isomorphic if the characters in s can be replaced to get t. Every occurrence of a character must map to the same character, and no two characters may map to the same character (a one-to-one mapping). Return false if either string is null or the lengths differ.

Example 1:

Input: s = 'egg', t = 'add' Output: true Explanation: e maps to a, g maps to d. The mapping is consistent throughout.

Example 2:

Input: s = 'foo', t = 'bar' Output: false Explanation: o would need to map to both a and r, which is not allowed.

Example 3:

Input: s = 'paper', t = 'title' Output: true Explanation: p maps to t, a maps to i, e maps to l, r maps to e. Consistent one-to-one mapping.

Example 4:

Input: s = 'ab', t = 'a' Output: false Explanation: Different lengths are never isomorphic.
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay August 2026

Contest runs August 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In