Tensorum
YouTubeகற்கத் தொடங்குங்கள்
LeetCode 205 · Hashing / Frequency

Isomorphic Strings

LeetCode 205 · எளிது · தீர்வு, intuition & படிப்படியான வாக்த்ரூ

Compare 'last seen index' of s[i] and t[i].

எளிதுHash TableString
LeetCode இல் திற ↗

நான் Isomorphic Strings (LeetCode 205) ஐ இப்படித் தீர்த்தேன் — Hashing / Frequency பேட்டர்னின் ஒரு எளிது பிராப்ளம். கீழே: intuition, படிப்படியான approach, என் accepted Python கோட், animated test cases மற்றும் line-by-line debugger.

கீழேயுள்ள விளக்கம் ஆங்கிலத்தில் உள்ளது.

Intuition

Two strings are isomorphic if each character's pattern of appearances matches. Record the last index where each character appeared in s and in t; at every position those last indices must agree.

Approach

  1. 1

    Two maps: last index per character for s and for t.

  2. 2

    If the stored indices differ, the mapping breaks.

  3. 3

    Update both with the current index.

நான் எப்படித் தீர்த்தேன்

Last-seen indicesPythonO(n) time
class Solution:
    def isIsomorphic(self, s: str, t: str) -> bool:
        #if two letters from s and t match correctly, their previous occurance must match
        s_mpp = {}
        t_mpp = {}
        for i in range(len(s)):
            char_s = s[i]
            char_t = t[i]
            if s_mpp.get(char_s,-1)!=t_mpp.get(char_t,-1):
                return False
            s_mpp[char_s]=i
            t_mpp[char_t]=i
        return True
ஸ்டெப்-த்ரூ ஏற்றுகிறது…

Isomorphic Strings — அடிக்கடி கேட்கப்படும் கேள்விகள்

Isomorphic Strings பின்னாலுள்ள intuition என்ன?

Two strings are isomorphic if each character's pattern of appearances matches. Record the last index where each character appeared in s and in t; at every position those last indices must agree.

Isomorphic Strings (LeetCode 205) ஐ எப்படித் தீர்ப்பது?

1. Two maps: last index per character for s and for t. 2. If the stored indices differ, the mapping breaks. 3. Update both with the current index.

Isomorphic Strings இன் time மற்றும் space complexity என்ன?

Time: O(n). Space: O(1) — bounded alphabet. (Accepted approach: Last-seen indices.)

Isomorphic Strings இல் பொதுவான தவறுகள் என்ன?

Checking only one direction misses cases like 'ab' → 'aa'.