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 October 2026 (Oct 4–15)Sponsored by FLXBL
Contest runs October 4 - 15. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 12 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.