Isomorphic Strings | Simple Thought Process | Leetcode 205| LinkedIn | codestorywithMIK

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • Whatsapp Community Link : www.whatsapp.com/channel/0029...
    This is the 28th Video of our Playlist "Leetcode Easy".
    In this video we will try to solve an easy map Problem :
    Isomorphic Strings | Simple Thought Process | Leetcode 205| LinkedIn | codestorywithMIK
    I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Also, please note that my Github solution link below contains both C++ as well as JAVA code.
    Problem Name : Isomorphic Strings | Simple Thought Process | Leetcode 205| LinkedIn | codestorywithMIK
    Company Tags : LinkedIn
    My solutions on Github(C++ & JAVA) : github.com/MAZHARMIK/Intervie...
    Leetcode Link : leetcode.com/problems/isomorp...
    Approach Summary :
    This code implements a solution to determine whether two given strings, 's' and 't', are isomorphic. Isomorphic strings are those that can be mapped to each other by replacing characters while preserving the order.
    The approach involves using two unordered maps, 'mp1' and 'mp2', to store mappings from characters in 's' to characters in 't', and vice versa, respectively. It iterates through the characters of both strings simultaneously. For each pair of characters, it checks whether the mappings stored in 'mp1' and 'mp2' conflict with the current characters. If there is a conflict (i.e., if the mappings are inconsistent), it returns false, indicating that the strings are not isomorphic. If no conflict is found after iterating through all characters, it returns true, indicating that the strings are isomorphic.
    Overall, the approach efficiently determines whether the given strings are isomorphic by maintaining mappings between corresponding characters and checking for conflicts.
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My Recursion Concepts Playlist : • Introduction | Recursi...
    My Sliding Window Playlist : • Count Occurrences of A...
    My GitHub Repo for interview preparation : github.com/MAZHARMIK/Intervie...
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    Subscribe to my channel : / @codestorywithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    ✨ Timelines✨
    00:00 - Introduction
    3:42 - Thought Process
    6:47 - Corner Case Example 1
    12:21 - Corner Case Example 2
    15:04 - Coding it up
    #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024

Komentáře • 53

  • @rohitrajput2097
    @rohitrajput2097 Před 14 dny +2

    what an amazing expaliation

  • @aritrakar2492
    @aritrakar2492 Před 2 měsíci +2

    thank you bhaiyaa , corner cases dekhke hi samaj gaya kaha code phassa tha mera .

  • @NeerajKumar-cj6ky
    @NeerajKumar-cj6ky Před 3 měsíci +6

    I subsrcibed your channel 8 month ago and the energy of teaching remains the same.

  • @gui-codes
    @gui-codes Před 3 měsíci +1

    nice. I also failed the same test case and then figured out the problem.

  • @soumyadwipsom5014
    @soumyadwipsom5014 Před 3 měsíci

    Thank you sir for sharing your important time with us ❤

  • @EB-ot8uu
    @EB-ot8uu Před 3 měsíci

    kaafi tricky Problem statement tha. thanks for making it easy

  • @gauravbanerjee2898
    @gauravbanerjee2898 Před 3 měsíci

    Thanks a lot bhaiya ❤❤

  • @tutuimam3381
    @tutuimam3381 Před 3 měsíci +1

    Thanks a lot

  • @oqant0424
    @oqant0424 Před 3 měsíci +4

    Solved it on my own
    Came here to learn optimisation
    Thanks :)

  • @ugcwithaddi
    @ugcwithaddi Před 3 měsíci

    Thank you ☺️

  • @avtarchandra2407
    @avtarchandra2407 Před 3 měsíci

    You are lovely mik ....thanks

  • @wearevacationuncoverers
    @wearevacationuncoverers Před 3 měsíci

    nice one

  • @thaman701
    @thaman701 Před 3 měsíci +6

    Java code guyz...
    class Solution {
    public boolean isIsomorphic(String s, String t) {
    int n=s.length();
    int m=t.length();
    if(n!=m) return false;
    HashMap mp=new HashMap();
    for(int i=0;i

  • @shloksuman8164
    @shloksuman8164 Před 3 měsíci +1

    even i tried using map, and mapped the frequency of both the strings. Then iterated over a string to to check any mismatch in frequency. passed 43/45 testcases. got stuck at the preserving order point , which was i guess the crux of the problem. thanks for solution

  • @tushartyagi4965
    @tushartyagi4965 Před 3 měsíci +2

    🔥🔥🔥🔥🔥

  • @adityaraj-zm7zk
    @adityaraj-zm7zk Před 3 měsíci

    @ codestorywithMIK bhaiya ye orthogonal greedy algo ka question kaha se kare and pattern of this question

  • @abhijitroy1958
    @abhijitroy1958 Před 3 měsíci

    can we use the find function in such a way that when we are searching for the first string element we can also check if the associated elements with it also exists or not

  • @souravjoshi2293
    @souravjoshi2293 Před 3 měsíci

    I was able to solve this 🙂

  • @Mohit-fe5hx
    @Mohit-fe5hx Před 3 měsíci

    november se ye question ko 6 attempt ho gye the wrong submission k..lfinally aaj clear hua

  • @harshavshah7929
    @harshavshah7929 Před 3 měsíci

    Bro pls
    Longest substring with atleast k repeating character ka ek video bana do

  • @shashiraj6226
    @shashiraj6226 Před 3 měsíci +1

    Sir can you tell me which editor do you use while explaining?
    It is really very clear explanation. Thank you.

  • @gaganjasuja1602
    @gaganjasuja1602 Před 3 měsíci +1

    Can you give a solution using bit manipulation??

  • @Nofaltuguy1
    @Nofaltuguy1 Před 3 měsíci

    i have a doubt will there a problem if length of s and t are different????

  • @kushagrapandey8898
    @kushagrapandey8898 Před 3 měsíci

    10:22 kya hum ek hi map me value ke through key ko ni check kr skte? Jaise key se value check kr rhe? 🤔

    • @gui-codes
      @gui-codes Před 3 měsíci +1

      No, because we need something to distinguish that the character I see in the map belongs to s or t

  • @subhajitdey135
    @subhajitdey135 Před 3 měsíci

    Another approach but same space and time complexity :)
    bool f(string s,string t){
    int size1=s.size(),size2=t.size();
    if(s==t) return true;
    unordered_mapmp;
    unordered_maptaken;
    for(int i=0;i

  • @mohdafzal4017
    @mohdafzal4017 Před 2 měsíci

    Why 256 as size ( when both capital and small letters are their ). i could understand 60(65-124). Please tell me

    • @codestorywithMIK
      @codestorywithMIK  Před 2 měsíci

      In ASCII, for example, there are 128 characters, but if you include extended ASCII, there are 256 characters. This includes both uppercase and lowercase letters, digits, punctuation marks, and control characters. So, to ensure that you can handle both lowercase and uppercase letters, you might use an array size of 256 to cover all possibilities.

  • @FifthArima
    @FifthArima Před 3 měsíci +1

    man, this question confused the hell out of me.

  • @as2002ajaysingh
    @as2002ajaysingh Před 3 měsíci

    if some one want a simple solution with not many condition are -
    class Solution {
    public:
    bool isIsomorphic(string s, string t) {
    vectormark(257,false);
    vectorc(257,' ');
    for(int i = 0;i

  • @layathal7460
    @layathal7460 Před 3 měsíci

    sir, here we are taking 2 additional maps right? So how the space complexity is still 0(1) ?

    • @akshay3841
      @akshay3841 Před 3 měsíci

      With 2 additional maps, its O(2 x 1(for limited characters)) so = 0(1).

    • @wearevacationuncoverers
      @wearevacationuncoverers Před 3 měsíci

      Because the constraints says that there will be only valid ascii characters in the string. We have only 256 ASCII characters. so map size will never exceed 256. Hence constant.

    • @gui-codes
      @gui-codes Před 3 měsíci

      s and t consist of any valid ascii character.

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Před 3 měsíci

    class Solution {
    public void create(char[]arr){
    char start='a';
    char[]mp=new char[256];
    for(int i=0;i

  • @dhruvrawat7023
    @dhruvrawat7023 Před 3 měsíci

    class Solution {
    public:
    bool isIsomorphic(string s, string t) {
    int sn = s.size();
    int tn = t.size();
    if(sn != tn){
    return false;
    }
    unordered_map mp;
    vector ta(128, false);
    for(int i = 0; i < sn; i++){
    char sc = s[i];
    char tc = t[i];
    if(mp.find(sc) == mp.end()){
    if(ta[tc] == true){
    return false;
    }
    mp[sc] = tc;
    ta[tc] = true;
    }
    else{
    if(mp[sc] != tc){
    return false;
    }
    }
    }
    return true;
    }
    };

  • @kungagyaltsenlachungpa8915
    @kungagyaltsenlachungpa8915 Před 3 měsíci +1

    s = "paper", t = "title", 'e' is alreday mapped with ''l' and and 'r' is mapped with 'e'? 2 different character mapped with same character?

    • @HossainAhmedSiam-ot5jr
      @HossainAhmedSiam-ot5jr Před 3 měsíci

      (e->L ) making pair in hash1. (L->e) making pair in hash2.
      now (r->e) making pair in hash1 and (e->r) in hash2.
      are you noticed that, "e" not appear in hash2 before, where you adding now .
      "e" as a key existing in different hash
      hash1 hash2
      e-->L L-->e
      r-->e e-->r

    • @gui-codes
      @gui-codes Před 3 měsíci

      @@HossainAhmedSiam-ot5jr thanks bro

  • @learningbuddy8575
    @learningbuddy8575 Před 3 měsíci

    What if string s= "abc" and string t="bas"??

    • @gui-codes
      @gui-codes Před 3 měsíci +1

      a -> b
      b -> a
      c -> s
      No same character in s is matched with different characters in t. So it's true.

  • @subhamcoder
    @subhamcoder Před 3 měsíci

    sir yee approach me kya galati haii
    mapmp1,mp2;
    int n=s.size();
    vectorv(256,1);
    for(int i=0;i

  • @shraban8508
    @shraban8508 Před 3 měsíci

    You haven’t uploaded this map code in github repo rather you have added the same arraylist code twice. Pls modify.

  • @devmadaan5146
    @devmadaan5146 Před 3 měsíci +2

    kyaa haal h bhai ( aap software engineer ban jaun na ...paise chhapo daba ke) khair fir yt mat choddna (LG jayenge fur mere)

  • @helpmore9389
    @helpmore9389 Před 3 měsíci

    @codestorywithMIK #codestorywithMIK
    Thank you bhaiya to make difficult question, easy.
    Would you please make the video for this question czcams.com/video/2ISNCDJEgqQ/video.html
    As the solutions available for this is very less, and also complicated.
    Hope to get the solution for this question soon.
    Thank you so much for giving time to read this and think about it.

    • @_FruitBasket
      @_FruitBasket Před 3 měsíci

      bhai yeh link toh issi video ka hai

    • @gui-codes
      @gui-codes Před 3 měsíci

      link is of this video only

  • @_FruitBasket
    @_FruitBasket Před 3 měsíci +1

    thank you for existing

  • @yashagarwal9784
    @yashagarwal9784 Před 3 měsíci

    Important Substitue:
    I think we can Replace Map2 with unordered_set. It can work.
    Here is the updated code:
    class Solution {
    public:
    bool isIsomorphic(string s, string t) {
    int n = s.size();
    unordered_map mp;
    unordered_set mapped;
    for (int i = 0; i < n; i++) {
    if (mp.find(s[i]) == mp.end()) {
    if (mapped.find(t[i]) != mapped.end())
    return false;
    mp[s[i]] = t[i];
    mapped.insert(t[i]);
    } else {
    if (mp[s[i]] != t[i])
    return false;
    }
    }
    return true;
    }
    };