Skip to main content

Command Palette

Search for a command to run...

Unraveling Isomorphic Strings: A Deep Dive into LeetCode Problem 205

Published
1 min read
A

BTech CSE student at IIIT Ranchi | Aspiring Software Engineer | Passionate about coding, building innovative projects, and solving real-world problems through technology. Currently diving into web development, Machine learning and deep learning. Always learning, creating, and pushing boundaries! #Tech #Coding

#isomorphic_strings??

Exploring the concept of isomorphic strings can be both intriguing and challenging. In this article, we delve into LeetCode Problem 205, which focuses on understanding and solving the problem of isomorphic strings. By examining this problem, we aim to provide a comprehensive guide to help you grasp the intricacies involved and enhance your problem-solving skills

class Solution {
public:
    bool isIsomorphic(string s, string t) {
        if(s.length()!=t.length()) return false;
        vector<int> v(150,1000);//dummy value..1000
        for(int i=0;i<s.length();i++){
            int idx = (int)s[i];
            if(v[idx]==1000) v[idx] = (s[i]-t[i]);
            else if((s[i]-t[i])!=v[idx]) return false;
        }
        //empty the vector..
        for(int i=0;i<150;i++){
            v[i] = 1000;
        }
        //doing same check for t also..
        for(int i=0;i<t.length();i++){
            int idx = (int)t[i];
            if(v[idx]==1000) v[idx] = (t[i]-s[i]);
            else if((t[i]-s[i])!=v[idx]) return false;
        }

        return true;
    }
};

On leetcode this is an easy category problem but not as easy I think this should be a medium category problem on leetcode..

In conclusion, understanding isomorphic strings through LeetCode Problem 205 offers valuable insights into string manipulation and mapping techniques. By mastering this problem, you can enhance your problem-solving skills and gain a deeper appreciation for the complexities involved in string-related algorithms. This exploration not only aids in tackling similar challenges but also strengthens your overall coding proficiency.

More from this blog

Untitled Publication

28 posts

Currently pursuing Bachelor of technology (Computer science and Engineering) from INDIAN INSTITUTE OF INFORMATION TECHNOLOGY RANCHI,JHARKHAND..