Isomorphic Strings
Updated
Problem statement
Given two strings s and t, determine whether they are isomorphic.
The strings are isomorphic when every character in s can be replaced consistently to produce t without changing character positions. Every occurrence of one character must map to the same character, and two different characters from s cannot map to the same character in t. A character may map to itself.
Function
isIsomorphic(s: String, t: String) → booleanExamples
Example 1
s = "egg"t = "add"return = trueMap 'e' to 'a' and 'g' to 'd'. Applying those substitutions consistently produces t.
Example 2
s = "f11"t = "b23"return = falseThe character '1' would need to map to both '2' and '3', so no consistent mapping exists.
Example 3
s = "paper"t = "title"return = trueThe repeated-character pattern is identical in both strings, and each character has one distinct position-preserving mapping.
Constraints
1 <= s.length <= 5 * 10^4t.length == s.lengthsandtcontain valid ASCII characters.
More Remitly interview questions
Similar questions at other companies
- Non-Repeating CharacterAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
- Count a User's Actions in an Event LogMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
- First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
- Minimum Replacements to Make Two Strings AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions