Minimum Window Substring | Google | Leetcode 76

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024
  • This is the 5th Video of our Sliding Window Playlist. This is one of the best Qns on Sliding Window and hence the most popular one.
    The interesting Problem is - "Minimum Window Substring" | Leetcode 76
    We will do live coding after explanation and see if we are able to pass all the test cases.
    Problem Name : Minimum Window Substring | Leetcode 76
    Company Tags : Google, Amazon, Microsoft, Codenation, FactSet, , Atlassian, MakeMyTrip, Streamoid Technologies, Media.net, Airbnb
    My solutions on Github(C++ & JAVA) : github.com/MAZ...
    Leetcode Link : leetcode.com/p...
    GfG Link : practice.geeks...
    My DP Concepts Playlist : • Roadmap for DP | How t...
    My Graph Concepts Playlist : • Graph Concepts & Qns -...
    My GitHub Repo for interview preparation : github.com/MAZ...
    Subscribe to my channel : / @codestorywithmik
    Instagram : / codestorywithmik
    Facebook : / 100090524295846
    Twitter : / cswithmik
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
    ✨ Timelines✨
    00:00 - Introduction
    #codestorywithMIK
    #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 #2024 #newyear #RecursionExplained #CodingJourney #Programming101 #TechTalks #AlgorithmMastery #Recursion #Programming #Algorithm #Code #ComputerScience #SoftwareDevelopment #CodingTips #RecursiveFunctions #TechExplained #ProgrammingConcepts #CodeTutorial #LearnToCode #TechEducation #DeveloperCommunity #RecursiveThinking #ProgrammingLogic #ProblemSolving #AlgorithmDesign #CSEducation

ความคิดเห็น • 107

  • @Peter-od1rm
    @Peter-od1rm ปีที่แล้ว +30

    Hope whoever search this question , yt recommend your solution so everyone can come to know this masterpiece, amazing , wonderful solution that you have created. Truly amazing way of explaining thanks dude to help us out in such a easy way .
    Wish you infinite success ❤

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Thank you so much 😇❤️
      I have pinned your comment so that others could see ❤️❤️

    • @aws_handles
      @aws_handles 7 หลายเดือนก่อน

      Thanks to TH-cam for recommending this to me 🔥🔥

    • @user-ub2is4rs4x
      @user-ub2is4rs4x 7 หลายเดือนก่อน

      Now i only search in this channel for any problem. This is a rare gold mine

  • @souravjoshi2293
    @souravjoshi2293 ปีที่แล้ว +21

    This dude is a gem. The effort you put in while explaining is amazing. The most hardworking dry run ever seen in a channel.

  • @rohan8758
    @rohan8758 23 วันที่ผ่านมา +2

    Awesome Mazhar bhaiyan, I have seen video solution on the two very famous DSA channel but according to me, your explanation beats their explanation in terms of making others to understand it, which makes you stand out from crowd & put you into very great teacher of DSA of Asia continent! Hats off to you 🙌🙌

  • @mirdulswarup9065
    @mirdulswarup9065 ปีที่แล้ว +13

    Let me say this, not every youtuber does a code along. Appreciate it sir. You have calming voice which makes understanding of problem much better XDDD. Plus you dont try to teach in english(Hindi all the way). THANKSSSS A LOTT. please dont stop making videos.
    Just a suggestion please discuss the time complexities also and hints of alternative solutions

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +2

      Feedback taken Mridul. Thanks a lot for your precious words.

  • @saiky_111
    @saiky_111 ปีที่แล้ว +7

    After searching this problem, when i saw you made a video on this, my eyes lit up😊

  • @tanujasharma1262
    @tanujasharma1262 26 วันที่ผ่านมา +1

    Best explanation on youtube

  • @TheMdaliazhar
    @TheMdaliazhar 3 หลายเดือนก่อน +1

    I have watched multiple youtube videos before coming here and didn't understand. I was about to give up that its not my cup of tea. Now your explanation made my day.
    Bhai maja aa gaya. Thanks itna achcha video banane ke liye.

    • @codestorywithMIK
      @codestorywithMIK  3 หลายเดือนก่อน

      Never ever give up ❤️❤️❤️

  • @Momentsofmagic28
    @Momentsofmagic28 7 หลายเดือนก่อน +1

    This is GOLD. Best explanation over internet.

  • @tusharsingh3063
    @tusharsingh3063 หลายเดือนก่อน

    Hey bro
    You are the best explainer
    Please keep it up
    Mai to fan ho gya aapka

  • @user-xo5xo9ow4q
    @user-xo5xo9ow4q 21 วันที่ผ่านมา

    wow an excellent teaching method love it

  • @amanpahari690
    @amanpahari690 5 หลายเดือนก่อน +1

    liked ur flow in the vedio and the way of teaching is great.Thanks

  • @viveksingh_01
    @viveksingh_01 7 หลายเดือนก่อน +3

    Couldn't solve it even after seeing other youtuber's explanation but after seeing your explanation I could solve it easily

    • @codestorywithMIK
      @codestorywithMIK  7 หลายเดือนก่อน +2

      🙏🙏❤️❤️ so glad to hear this

    • @viveksingh_01
      @viveksingh_01 7 หลายเดือนก่อน

      @@codestorywithMIK 🙏

  • @kingkohli7175
    @kingkohli7175 17 วันที่ผ่านมา +1

    awesome brother

  • @star-dust1702
    @star-dust1702 19 วันที่ผ่านมา +1

    Hi sir, can you please make a video on the LC 727 Minimum Window Subsequence (premium) / GFG version of it? Your explanations are amazing and I am struggling to solve that problem sir

  • @KrishnaSingh-je8pu
    @KrishnaSingh-je8pu 2 หลายเดือนก่อน

    Bhai aap kamal ke ho....kya explanation dete ho yrrr...gajab

  • @vaishalisahu2598
    @vaishalisahu2598 7 หลายเดือนก่อน

    A good teacher can make everything simple and joyful ✨ Thankyou so much sirr❤ you ended the fear of hard problems✨

  • @Sanjaysview
    @Sanjaysview 7 หลายเดือนก่อน +2

    Excellent explanation my brother thank you so much

  • @smsyd853
    @smsyd853 5 หลายเดือนก่อน

    Thank you boss i just watched 20 min of your viideo and then solved it on my own.

  • @nobbiesid1324
    @nobbiesid1324 11 หลายเดือนก่อน +1

    Again best Explaination Thanku bhya 🥰

  • @S3aw0lf
    @S3aw0lf 7 หลายเดือนก่อน

    Had to watch twice but explanation was superb as always with each minute details and understood the whole story clearly

  • @anshumaan1024
    @anshumaan1024 7 หลายเดือนก่อน +1

    bhaiya boht acha explaint kiya hai, bs TC aur SC bhi bta dete toh maza a jaata 🙂🙂
    TC -> O(m+n)
    SC-> O(m+n) , because map will store characters of both strings

    • @surajsidar3280
      @surajsidar3280 2 หลายเดือนก่อน

      To reduce space complexity you can only store characters of t in map.
      While iterating through the characters of s string you have to check whether the key exist in map or not
      (But TC of finding key exist or not is O(log n))

  • @abhisheknandann
    @abhisheknandann ปีที่แล้ว +1

    Soothing voice+great explanation=🔥

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Means a lot. Thank you so much 😇❤️🙏

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 7 หลายเดือนก่อน

    This is nothing but a MASTERPIECE 🔥

  • @ShivamGupta-cx3hy
    @ShivamGupta-cx3hy ปีที่แล้ว +3

    Thank You sir ☺️

  • @codestorywithMIK
    @codestorywithMIK  ปีที่แล้ว +4

    Explanation : 3:00

  • @pulastyadas3351
    @pulastyadas3351 ปีที่แล้ว +2

    Really hard made easy by your explanation… 😊😅❤please continue ❤

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Thank you so much ❤️😇🙏

    • @pulastyadas3351
      @pulastyadas3351 ปีที่แล้ว

      @@codestorywithMIK could you please cover leetcode 726 - no of atoms problem... please

  • @sidharthdhiman4522
    @sidharthdhiman4522 ปีที่แล้ว +1

    I also have another approach wehre instead you have counter make the the use of another array and keep adding characters until the m1 == target_map and if becomes equal try to remove the characters.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Awesome Sidharth. ❤️❤️
      Thanks a lot for sharing your idea.
      Would you also please share the code

  • @theOmKumar
    @theOmKumar 7 หลายเดือนก่อน

    thank you for the optimised approach , i came up with this :
    class Solution {
    public:
    bool isEqual(vector &window){
    for(int i = 0; i < 128; i++){
    if (window[i] > 0){
    return false;
    }
    }
    return true;
    }
    string minWindow(string s, string t) {
    if (s.size() < t.size()) return "";
    vector count(128,0);
    for(auto &ch : t){
    count[ch]++;
    }
    string ans = "";
    int start = 0, end = 0, minSize = INT_MAX;
    while(end < s.size()){
    //update curr element
    count[s[end]]--;
    //shrink window
    while(count[ s[start] ] < 0 && start < size(s)){
    count[s[start++]]++;
    }
    //update valid window to ans
    if(end-start+1 < minSize && isEqual(count)){
    ans = s.substr(start,end-start+1);
    minSize = ans.size();
    }
    end++;
    }
    return ans;
    }
    };
    */

  • @see2672
    @see2672 ปีที่แล้ว +1

    Sir please make a video on minimum window subsequence.Thank you.

  • @facttecher3039
    @facttecher3039 4 หลายเดือนก่อน

    Nice explanation SIRJI.

  • @TheCurrencyNomad1
    @TheCurrencyNomad1 8 หลายเดือนก่อน

    Meri jaan mja aa gya solution mai..kya mast smjhahya hai

  • @retromonk88
    @retromonk88 ปีที่แล้ว +1

    Top Tier explanation jod>>>

  • @nishantdehariya5769
    @nishantdehariya5769 5 หลายเดือนก่อน

    very nice

  • @yashdeshmukh6191
    @yashdeshmukh6191 7 หลายเดือนก่อน +1

    Sir how you are so much consistent... What do you do to be so focused...? Yoga, meditation or anything! I am surprised 🤯 sir. Please if you don't mind please share your routine with me. It would be helpful.

    • @codestorywithMIK
      @codestorywithMIK  7 หลายเดือนก่อน +1

      I’ll definitely make a video on that 🙏🙏❤️❤️

  • @helloworld6208
    @helloworld6208 7 หลายเดือนก่อน +1

    Excellent sir

  • @ehasah6840
    @ehasah6840 2 หลายเดือนก่อน +1

    Amazing explanation. Thank you very much.
    I have a question - why did we kept track of frequencies of all characters (which are not in t string)? Don't we just need the characters in t string? I was just curious.

    • @vineetjadhav1785
      @vineetjadhav1785 หลายเดือนก่อน

      Yes ur Right, I thought the same way, coz storing the unwanted characters in the map also can increase space complexity and make code large.

  • @kunalpatil.24
    @kunalpatil.24 7 หลายเดือนก่อน +1

    Thank you !

  • @mirdulswarup9065
    @mirdulswarup9065 ปีที่แล้ว +2

    Ek cheez please bta dijiye, if abc ki aabc hota in which a is repeating toh count characters wala jo variable hai uski length 4 hi jaati ya 3 jaati since unique characters sirf 3 hai

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Uski length 4 Jaati. Kyoki hume poori string 't' chase in 's' . 't' ki length 4 hai to poori 4 length Jaati. I hope I could answer your qn.
      Thanks a lot again for your comments. ❤

  • @secretdreams201
    @secretdreams201 7 หลายเดือนก่อน

    Thankyou for this amazing explanation.

  • @Gyan_ki_dukaan-sx6le
    @Gyan_ki_dukaan-sx6le 5 หลายเดือนก่อน

    awesome dude!! couldn't think it in first go.. how long did it took to devise this soln urself?

  • @om3585
    @om3585 7 หลายเดือนก่อน

    Salute hai bhai aapko😎

  • @trayambrathore7735
    @trayambrathore7735 7 หลายเดือนก่อน

    nice qn and good explaination

  • @sparshyadav9709
    @sparshyadav9709 5 หลายเดือนก่อน

    Understood.

  • @gagankaushik556
    @gagankaushik556 หลายเดือนก่อน

    thnx

  • @girikgarg8
    @girikgarg8 11 หลายเดือนก่อน +1

    Nice explanation!

  • @prateekgirilateralentry5865
    @prateekgirilateralentry5865 4 หลายเดือนก่อน

    Thank You Sir .

  • @engg.5111
    @engg.5111 ปีที่แล้ว +1

    Maja agyaa bro🔥🔥

  • @aadarshpandit2929
    @aadarshpandit2929 7 หลายเดือนก่อน

    wow sir so nice explanation

  • @divyanshsagar
    @divyanshsagar ปีที่แล้ว +1

    nicely explained!

  • @k-CE-OmkarPathak
    @k-CE-OmkarPathak 7 หลายเดือนก่อน +1

    🙏🙏🙏🙏

  • @ugcwithaddi
    @ugcwithaddi 7 หลายเดือนก่อน

    insane explanation

  • @atharvapimple9262
    @atharvapimple9262 7 หลายเดือนก่อน +1

    Java program
    class Solution {
    public String minWindow(String s, String t) {
    int n=s.length();
    if(t.length()>n){
    return "";
    }
    HashMap map=new HashMap();
    for(char ch:t.toCharArray()){
    map.put(ch,map.getOrDefault(ch,0)+1);
    }
    int required=t.length();
    int i=0,j=0;
    int minWindow=Integer.MAX_VALUE;
    int start_i=0;
    // exploring window
    while(j0){
    required--;
    }
    map.put(ch,map.getOrDefault(ch,0)-1);
    while(required==0){
    // shrinking window
    int curr=j-i+1;
    if(minWindow > curr){
    minWindow=curr;
    start_i=i;
    }
    char c=s.charAt(i);
    map.put(c,map.getOrDefault(c,0)+1);
    if(map.getOrDefault(c,0)>0){
    required++;
    }
    i++;
    }
    j++;
    }
    return minWindow==Integer.MAX_VALUE? "" : s.substring(start_i,start_i+minWindow);
    }
    }
    Done

  • @swasthikbhatt9833
    @swasthikbhatt9833 ปีที่แล้ว +1

    Thank you so much bro 🥰

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Thank you so much
      I am glad it helped 😇❤️🙏

  • @HuzaifaBilal-fo7zc
    @HuzaifaBilal-fo7zc 4 หลายเดือนก่อน

    This solution was showing TLE in GFG so it got optimized by using array...

  • @gauravbanerjee2898
    @gauravbanerjee2898 ปีที่แล้ว +1

    Crystal clear explanation thanks a lot bhaiya ❤❤ but bhaiya problem leetcode pe to submit hogya but gfg pe kyu TLE mar gya 🥹

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Thank you 😇❤️
      Can you share gfg code that you are trying ?

    • @gauravbanerjee2898
      @gauravbanerjee2898 ปีที่แล้ว +1

      @@codestorywithMIK Yes bhaiya sure, here it is
      class Solution
      {
      public:
      //Function to find the smallest window in the string s consisting
      //of all the characters of string p.
      string smallestWindow (string s, string t)
      {
      // Your code here
      int n =s.length();
      if(t.length()>n)return"";
      unordered_mapmp;
      for(char &ch:t){
      mp[ch]++;
      }
      int requiredCount=t.length();
      int i=0, j=0;
      int minwindowSize =INT_MAX;
      int start_i=0;
      while(j0){
      requiredCount--;
      }
      mp[ch]--;
      while(requiredCount==0){
      int curWindowSize = j-i+1;
      if (minwindowSize>curWindowSize){
      minwindowSize = curWindowSize;
      start_i=i;
      }
      mp[s[i]]++;
      if(mp[s[i]]>0){
      requiredCount++;
      }
      i++;
      }
      j++;
      }
      return minwindowSize==INT_MAX?"":s.substr(start_i,minwindowSize);
      }
      };

    • @gauravbanerjee2898
      @gauravbanerjee2898 ปีที่แล้ว

      @@codestorywithMIK any updates bhaiya??

  • @user-iv3jg1jn9z
    @user-iv3jg1jn9z 2 หลายเดือนก่อน

    Its a beautiful explaination but the logic is tough to take in

  • @priyanshusingh3316
    @priyanshusingh3316 7 หลายเดือนก่อน

    complexity = O(n*2) ~ O(n) ? where n is length of s?
    my thinking, every element gets added and deleted/not deleted in the sliding window
    so for every n, at worst we have 2 operations

  • @user-vk7wb6hg9b
    @user-vk7wb6hg9b 5 หลายเดือนก่อน

    The same problem when I tried submitting on gfg using this solution gives TLE with 4000/5000 tc passed, please suggest me how can I optimise it more

  • @shabananoor9423
    @shabananoor9423 7 หลายเดือนก่อน

    ❤❤

  • @user-kr7lw4yo9o
    @user-kr7lw4yo9o 8 หลายเดือนก่อน

    Bro what does that INT_MAX does i didnt get the last return part what are we actually checking can someone please help me

  • @aws_handles
    @aws_handles 7 หลายเดือนก่อน

    ❤️❤️

  • @codeandtalk6
    @codeandtalk6 7 หลายเดือนก่อน

    ❤❤❤

  • @atifakhtar8828
    @atifakhtar8828 11 วันที่ผ่านมา

    mazhar bhai biryani khaoge btao??? #GODOFDSA

  • @bhartendupant8859
    @bhartendupant8859 7 หลายเดือนก่อน

  • @HeetVichhivora
    @HeetVichhivora 7 หลายเดือนก่อน +1

    bhaiya amazing ,aapka linkedin ?

    • @codestorywithMIK
      @codestorywithMIK  7 หลายเดือนก่อน

      Thank you 😇
      www.linkedin.com/in/mazhar-imam-khan-95a34ab3?

  • @chillkro25
    @chillkro25 7 หลายเดือนก่อน

    Can i take queue instead of deque

  • @ayushivishwakarma9101
    @ayushivishwakarma9101 7 หลายเดือนก่อน

    how to do these type of question without watching tutorial ??

  • @jagadeeshp1163
    @jagadeeshp1163 10 หลายเดือนก่อน +1

    def minWindow(self, s: str, t: str) -> str:
    d={}
    count=0
    req_count=len(t)
    n=len(s)
    start=0
    min_size=inf
    for i in range(len(t)):
    d[t[i]]=d.get(t[i],0)+1
    i=0
    for j in range(len(s)):
    ch=s[j]
    if ch in d and d[ch]>0:
    req_count-=1
    d[ch]=d.get(ch,0)-1
    while(req_count==0):
    # shrink
    if j-i+1

  • @saiei
    @saiei 7 หลายเดือนก่อน

    //th-cam.com/video/3Bp3OVD1EGc/w-d-xo.html
    //we will use map on t to check if we need those letters or not,
    //we will use the concept of sliding window
    //we need to make user that all the eleemnts of t r present in s so we will use cound required that will be the length of the t
    //ur i and j will be at the benginging, j will go forward if ur count required is >1
    //ur i will move forward if ur count required

  • @HritikRaj-k6n
    @HritikRaj-k6n 20 วันที่ผ่านมา

    Java solution ??

  • @surajsharma-1554
    @surajsharma-1554 5 หลายเดือนก่อน

    ye approach gfg pe tle mar rhi hai

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 7 หลายเดือนก่อน

    public String minLength (String s,String t){
    int[]cnt=new int[128];
    int req=t.length(),left=-1,minLength=s.length()+1;
    for(char c:t.toCharArray())
    ++cnt[c];
    for(int l=0,r=0;r=0)
    --req;
    while(req==0){
    if(r-l+10)
    ++req;
    }
    }
    return left==-1?" ":s.substring(left,left+minLength);
    }
    tc=(m+n);m=t.length,n=s.length,
    sc=(m);
    🎉❤

  • @dineshkm7832
    @dineshkm7832 วันที่ผ่านมา

    Between D and B put D. And ur logic will not work as count vl be 1

  • @eron7850
    @eron7850 7 หลายเดือนก่อน

    me after watching this explanation " Swad++ "😂

  • @aiyappamn326
    @aiyappamn326 ปีที่แล้ว +2

    Explanation ka BHAGWAAN HE YE

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      I am glad my channel is helping ❤️😇🙏