Minimum Window Substring (Leetcode Hard) | Hashmap Interview Questions

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024
  • Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
    NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. Here you will learn about Minimum Window Substring problem using hashmaps and 2 pointer approach. In this question :
    1. You are given two strings s1 and s2 containing lowercase english alphabets.
    2. You have to find the smallest substring of s1 that contains all the characters of s2.
    3. If no such substring exists, print blank string("").
    To attempt and submit this question, click here: www.pepcoding....
    For a better experience and more exercises, VISIT: www.pepcoding....
    Have a look at our result: www.pepcoding....
    Follow us on our FB page: / pepcoding
    Follow us on Instagram: / pepcoding
    Follow us on LinkedIn: / pepcoding-education

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

  • @alfiyazahra4680
    @alfiyazahra4680 3 ปีที่แล้ว +35

    sir, your explanation is damn perfect.
    every time search for a coding solution, I wish I found pepcoding there.

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

      Glad to know that you liked the content and thank you for appreciating.
      The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
      So, keep motivating, keep learning and keep loving Pepcoding😊

    • @alfiyazahra4680
      @alfiyazahra4680 3 ปีที่แล้ว +3

      @@Pepcoding yes sir
      U r just awesome

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

    Very Engaging and DETAILED explanation! I am naturally Extra Focused during his videos.

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

    I think no one can explain these tricky solutions better then you sir ......... : )

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

      Thanks a lot, for better experience and well organised content sign up on nados.io and start learning.

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

    Sir aap great ho sir. Mene ek course lia tha, uss course ne itna confuse kar dia ki khud pe doubt hone laga.Firr aapki dekhi tab jaake samjh aane laga.Ab waha se questions dekh ke explanation ke liye pepcoding pe aata hoon

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

    you are the reason why i am getting interested in programming.
    thank you

  • @Akshitgupta1
    @Akshitgupta1 3 ปีที่แล้ว +36

    Hard question and simple explaination, maza aa gya sir💯

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

      thank you

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

      Superb explanation!

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

      Amazing explanation - this is an understatement!

  • @shivanivishwakarma2350
    @shivanivishwakarma2350 3 ปีที่แล้ว +6

    You explained this hard problem in such an easy way. Thankyou :)

  • @chandankumartandi3842
    @chandankumartandi3842 3 ปีที่แล้ว +9

    Thank you sir, for the content🤗... But one minor correction is required...While collecting the answers, the length will be i-j.......s1. substring(j+1, i-j)....

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

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

    sir you gave outstanding explanation with a simple code. love the way of your teaching
    :)

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

    Great explanation. I was scratching my head whole day reading about this solution online.

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

    Sir, Your explanation is one of the greatest thank you so much.

  • @mr.k6831
    @mr.k6831 2 ปีที่แล้ว +2

    Sir, you are the best🖤. Just understood the whole concept of the problem and approach within 6min. Great explanation

  • @minkalchaudhary1977
    @minkalchaudhary1977 3 ปีที่แล้ว +3

    I understood in half way you make hard question so easy.Thank you sir you are doing great job👍.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review - g.page/Pepcoding/review?rc

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

    C++ Solution with a few tweaks
    (1) -> Instead of storing ans as a string I stored its starting and ending index ( and length also for easy understanding)
    because I think .substr() takes much higher time than just updating 2-3 variables.
    GOOGLE SAYS-> substr(): Returns a string which is the copy of the substring. Its time complexity is O(N) where N is the size of the substring.
    (2) -> Instead of making map for curr stage made a frequency vector
    its size will be 58 => 26 capitals + 6 SPECIAL CHARACTERS IN BETWEEN + 26 small
    and to get the index from character do : char - 'A'
    SEE THE ASCII TABLE IF YOU DIDN'T GET THAT
    my LEETCODE submitted ans:
    class Solution {
    public:
    // two pointer acquire and release strategy
    string minWindow(string s, string t) {
    vector req(58,0); // char in t and there required frequency
    for(char c: t){
    req[c-'A']++;
    }
    vector curr(58,0); // freqency array (saves time than map) (26 + 26 +6 special char in between )
    int r = -1; // right pointer to acquire
    int l{-1}; // left pointer to release
    int rmc = t.length(); // required match count
    int cmc = 0; // current match count
    int slen = s.length();
    int anslen = 0;
    int al{-1};
    int ar{-1};
    for(int r{}; r< slen; r++){
    //acquire
    char cc = s[r]; // current char
    curr[cc-'A']++;
    if(curr[cc-'A'] r-l){
    anslen = r-l;
    ar = r;
    al = l;
    }
    l++;
    char cc = s[l]; // current char
    curr[cc-'A']--;
    if(curr[cc-'A'] < req[cc-'A']){
    cmc--;
    }
    }
    }
    string ans{""};
    if(ar != -1){
    ans = s.substr(al+1,ar-al);
    }
    return ans;
    }
    };

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

    The concept is very tricky and very useful for other problems as well. It gives a new perspective to solve a problem. Thank you :)

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

      yes it is really an importent concept which can get used in lot of other problems:
      If someone comment in future here I will get notify and I will revise this concept again

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

      @@Kashish_Batra Lag gai

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

    "Bina baat ki cheezien acquire ho rahi hai.." :D , bhai pareshaan ho gaya kuch dhang ka acquire nahi ho raha :D.
    Best way of explaining, love your videos :)

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

    I have seen a lot of video before landing here but you have given a very clear explanation .. great work man :)

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad it was helpful!

  • @ankushgupta630
    @ankushgupta630 3 ปีที่แล้ว +11

    This question seems simple but isn't. GG on explaining it!

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

    Thank you sir
    your explanation was so good that i build my own code 🙂
    public static String minWindow(String s, String t) {
    HashMap reqFreq = new HashMap();
    int reqMatch = t.length();
    for (char c : t.toCharArray()) reqFreq.put(c, reqFreq.getOrDefault(c, 0) + 1);
    String ans = "";
    HashMap workFreq = new HashMap();
    int i = -1, j = -1, currMatch = 0;
    while (i

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

    Do not remove the character from map1 ,if suppose the frequency is zero in map2 then it will take the default frequency 0 in map1 also and while comparing it will not decrement the mcnt and second thing is getDefaultOrZero function is incrementing the value on first hit itself to 1 instead of zero in map1 so containsKey method should be used for checking if the character exists in map or not then increment the value in else condition if it exists.

  • @brijpatel237
    @brijpatel237 3 ปีที่แล้ว +5

    watched till half and boom got the green tick! , thanks :-D

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

      Keep learning and Keep supporting.
      Will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms)

  • @ajaywadhwa3398
    @ajaywadhwa3398 3 ปีที่แล้ว

    Wow Sir !!! Mazaa hi aa gya kahin nahi mili t iski itni easy explanations .
    Sir ji tussi Great ho .

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

    nice explaination..but sir you dont need to substring it everytime as for large string it would drag your performance..you just need to store the start and end index

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

    Brilliant explanation!! Thank you sir

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

    C++ Concise. Easy to understand
    string minimumWindowSubstring(string str, string target) {
    int n = str.size();
    map map;
    for (char c : target)
    ++map[c];
    int minLen = n + 1;
    int count = 0;
    int k = map.size();
    string result = "";
    int i = 0, j = 0;
    while (j < n) {
    if (count < k) {
    if (map.count(str[j])) {
    --map[str[j]];
    if (map[str[j]] == 0)
    ++count;
    }
    ++j;
    }
    while (count == k) {
    if (minLen > j - i) {
    minLen = j - i;
    result = str.substr(i, j - i);
    }
    if (map.count(str[i])) {
    ++map[str[i]];
    if (map[str[i]] == 1)
    --count;
    }
    ++i;
    }
    }
    return result;
    }

    • @pulkitjain5159
      @pulkitjain5159 2 ปีที่แล้ว

      thanks this code was more understandable, I saw Aditya Verma Sir's SlidingWindow technique video but could'nt able to code it.Really thanks sir:)

    • @pratik.784
      @pratik.784 ปีที่แล้ว

      tle aajayega

  • @AyushRaj-pm1dz
    @AyushRaj-pm1dz 2 ปีที่แล้ว +7

    C++ Code same as the explained in the video :
    string minWindow(string s, string t) {
    string ans = "";
    unordered_map map2;
    for(auto c : t){
    map2[c]++;
    }
    int matchcount = 0;
    int desiredcount = t.length();
    unordered_map map1;
    int i=0,j=0;
    while(true){
    bool flag1 = false;
    bool flag2 = false;

    //acquire
    while(i

    • @techyguy7776
      @techyguy7776 2 ปีที่แล้ว

      I tried the same code but with i=-1 and j=-1 but somehow the flow skips the inside while loop do you have any idea on it?

    • @techyguy7776
      @techyguy7776 2 ปีที่แล้ว

      string smallestWindow (string s, string t)
      {
      // Your code here
      string ans="";
      unordered_map mp1;
      unordered_map mp2;
      int mct=0;
      int dmct=t.length();
      for(auto it : t)
      mp2[it]++;
      int i=-1;
      int j=-1;
      while(true){
      bool f1=false;
      bool f2=false;
      // cout

    • @ROHITKUMAR-xp2xe
      @ROHITKUMAR-xp2xe 2 ปีที่แล้ว

      @@techyguy7776 in while loop put extra (i==-1) condition i.e :- while(i==-1 or i

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

    you are a great teacher sir

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

    Every time I see his video on a topic I'm learning I am like, okay it will be cleared I can plan for next one. He is God 🙏

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

    Thanks a lot sir to make me understand this hard problem.

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

    The explanation was really excellent when I saw this question I was confused much after watching your video It's crystal clear Thank You Sir

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      Glad it helped! For better experience and precisely arranged content visit on nados.io

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

    Nice explanation sir.....thanks for making the video

  • @dineshsrivastava4508
    @dineshsrivastava4508 3 ปีที่แล้ว

    You make this problem is so easy for us. Thank you so much sir

  • @snehajain5562
    @snehajain5562 2 ปีที่แล้ว

    your explanation is very easy for this hard question ,thanks sir

  • @priyanshukumawat4142
    @priyanshukumawat4142 3 ปีที่แล้ว

    bhai likh ke deta hu mene phle bhi comment kia he ye pep coding just java me he isliye audience kam ho jati he wrna sach bolta hu sumeet sir jesa thought process built krke padhana rare he.code to koi bhi likh kar explain kr de par dhang se zero se smjha pana har kisi ke bas ki bat nhi h ... SALUTE SIR APKO !!!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.

    • @priyanshukumawat4142
      @priyanshukumawat4142 3 ปีที่แล้ว

      @@Pepcoding SURELY!!!

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

    Awesome explanation! Seriously great, you keep us glued to the video till the end.
    I had one ques what would be its time complexity?

    • @girikgarg1268
      @girikgarg1268 2 ปีที่แล้ว

      Yes same question, what would be the time complexity?

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

      O(n)

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

    superb explaination

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

    exceeds time limit on leet code, for case 266
    class Solution {
    public:
    string minWindow(string s, string t) {
    string result = "";
    /*step1 create a hash map of all characters in substring*/
    unordered_map map2;
    for(int k=0;k

  • @GunjanKumar-ls9ix
    @GunjanKumar-ls9ix 3 ปีที่แล้ว

    Hard Problems seems easy after your video, good job sir.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      th-cam.com/users/Pepcodingabout?view_as=subscriber

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

    I guess time complexity is O(n^2)
    Space : O(1)

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

    Hi,
    Isn't it that your code will fail for finding smallest string for the below:
    abcdefaghjklabce
    abce
    The answer should be abce which is present at the end however your program will return abcde.

  • @AmanKumar-wd2mq
    @AmanKumar-wd2mq ปีที่แล้ว

    best explaination❤

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

    Nice explanation!!

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

    Aap to bade heavy driver nikle

  • @pankajkohli9263
    @pankajkohli9263 3 ปีที่แล้ว

    Very nice video. A complex algorithm looks so simple and easy to implement. Please post more videos.
    Suggestion for next problem :
    Similar problem, just a twist the substring should contain the characters in the same order as pattern.
    If the solution is ready. Please send the link :)

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

    Really good explanation

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

    Kya explain Kiya h sir.. outstanding😊

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thankyou beta!
      I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @garimagarg9065
    @garimagarg9065 3 ปีที่แล้ว

    Sir, honestly aap humari hopes ko alive rkhte ho.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.

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

    We can also use array instead of hashmap..

  • @suhitgupta9429
    @suhitgupta9429 2 ปีที่แล้ว

    your explanation is very good but plz whenever you make videos please discuss the brut force approach first then the optimal. Most of the time in your videos you directly start with the optimal approach first.

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      Thanks a lot for your feedback, we will work on it. For better experience and precisely arranged content visit & sign up to nados.pepcoding.com

  • @VishalKumar-tn8ls
    @VishalKumar-tn8ls 2 ปีที่แล้ว

    Perfect explanation. Couldn't resist to comment

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek9398 3 ปีที่แล้ว

    nice explanation after watching so many videos this video is so much helpfullllll........

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

      Thankyou beta!
      If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

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

    great explanation sir, thank you very much.

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

    thanks bro, very good explanation. keep up the good work.

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

    Sir, what is the space and time complexity of the solution?

  • @ajeetworking
    @ajeetworking 3 ปีที่แล้ว

    the way you explain is superb..thanks

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      You are most welcome

  • @vivekkejriwal3321
    @vivekkejriwal3321 2 ปีที่แล้ว

    This man is clearly underrated

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      Hope you love the explanation, for better experience and well organised content visit - nados.io

  • @abhishekjha2182
    @abhishekjha2182 3 ปีที่แล้ว

    Your explanation is soo simple.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thank you so much. Keep learning, Keep growing and keep loving Pepcoding!😊

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

    Awesome Explaination indeed !!!

  • @rawat_ji5183
    @rawat_ji5183 2 ปีที่แล้ว

    easy to understand thank you sir

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

    EXPLANATION IS SUPERB BUT the code is taking too much time sir😢

  • @Ravi-ks7ev
    @Ravi-ks7ev ปีที่แล้ว +1

    acquire
    release
    repeat step1 and step2

  • @rohandevaki4349
    @rohandevaki4349 2 ปีที่แล้ว

    i got the logic before i saw the video, and i coded too, only few test cases were passing, i did a lot of dry run and modified my code, but still it was not working, in this case i should just follow the other approach and code?

  • @youngshahrukhkhan8179
    @youngshahrukhkhan8179 3 ปีที่แล้ว

    Very Nice Explanation.......Keep making videos

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @sadlyf2056
    @sadlyf2056 2 ปีที่แล้ว

    In c++ (-1

  • @NaveenKumar-os8dv
    @NaveenKumar-os8dv 2 ปีที่แล้ว

    Just how do you convert your thinking to code so "Easily", it looks like a piece of cake to you, but I am unable to do it, even after knowing the way to do it.

  • @pirangitharun8736
    @pirangitharun8736 3 ปีที่แล้ว

    Thank you so much. You explained it very clearly. and subscribed too :)

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

      Glad it was helpful! and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @mainakmondal5228
    @mainakmondal5228 2 ปีที่แล้ว

    Can't be better than this...No way...

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

    Done!

  • @faizan346
    @faizan346 3 ปีที่แล้ว +3

    the implementation is hard the question isn't :(. so many things to take care of .

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

    Time Complexity?

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

    This was lit🔥

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

    Thanku sir❤️❤️

  • @janhavipatil4971
    @janhavipatil4971 2 ปีที่แล้ว

    Thank you so much sir!

  • @satyamgupta1416
    @satyamgupta1416 3 ปีที่แล้ว

    why we are doing minus i.e while i

  • @virusnetic
    @virusnetic 3 ปีที่แล้ว

    we can return the string when releasing and the match (6) count is the same as the length of the substring (as its the best possible answer) ?

  • @rosansenapati-pl5hr
    @rosansenapati-pl5hr ปีที่แล้ว

    Great explanation sir but this is giving TLE in leetcode

  • @songs-pu9bq
    @songs-pu9bq 3 ปีที่แล้ว

    Lovely explanation brother🙌🙌🔥🔥

    • @yogeshyts
      @yogeshyts 3 ปีที่แล้ว

      jara submit kriyo ye code leetcode pe

  • @cavi8779
    @cavi8779 3 ปีที่แล้ว

    Loved ur explanation bhai

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      th-cam.com/users/Pepcodingabout?view_as=subscriber

  • @sravannayini4329
    @sravannayini4329 2 ปีที่แล้ว

    Nice explanation. May I know what is the tool you used for explaining the algorithm. I really liked the Tool.

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

    sir yeh sol gfg pr tle de rha , 10^5 pr nhi chl rha. Any idea why???

  • @indranilchakraborty5949
    @indranilchakraborty5949 3 ปีที่แล้ว

    You are great sir....👍👌👌....very cool explanation 😊😊.Sir Web Dev ka vedio kab ayega ??

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

      Very soon and Thanks alot beta Keep learning, Keep growing and keep loving Pepcoding!😊

    • @yogeshyts
      @yogeshyts 3 ปีที่แล้ว

      kbhi ni

  • @KB-zg8ho
    @KB-zg8ho 3 ปีที่แล้ว +1

    Sir in this question what is an alternative version of map.getordefault in c++ ?

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      ek fn likhna hoga agar count zero hai to saamne frequency 1 daal dein. nahi to badha dein

  • @loserfruit9663
    @loserfruit9663 3 ปีที่แล้ว

    Sir,You are best

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.

  • @sarangr8624
    @sarangr8624 3 ปีที่แล้ว

    Best explanation ever

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      I am glad. Keep learning. Keep supporting. Your kind words are the kind of motivation that truly help me in making more and more content. Especially, these days, not everybody is generous with motivating anybody either. It means a lot

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

    Im getting memory limit exceeded error, anyone can help?

  • @511-neelbutani9
    @511-neelbutani9 3 ปีที่แล้ว +1

    Sir why i

    • @aditikajale8514
      @aditikajale8514 3 ปีที่แล้ว

      no we are doing i++ inside the loop

  • @mishra1576
    @mishra1576 3 ปีที่แล้ว

    Best explanation 🙏🙏🔥🔥

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad you liked it

  • @ankoor
    @ankoor 3 ปีที่แล้ว

    Python Code:
    def minWindow( s, t):
    m = len(s)
    if m == 0:
    return ''"
    # Compute frequency of chars in t
    freqT = {}
    for c in t:
    freqT[c] = freqT.get(c, 0) + 1
    i = 0
    j = 0
    n = len(t)
    freqS = {}
    output = ''
    matchCount = 0
    while i < m:
    # Acquire chars and update of chars in s
    while i < m and matchCount != n:
    c = s[i]
    freqS[c] = freqS.get(c, 0) + 1
    if freqS[c]

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

    Sir, This will work with linear time complexity right ?

  • @theglamourhut
    @theglamourhut 3 ปีที่แล้ว

    Thankyou very much sir🙏

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Most welcome

  • @souravkumarshaw7090
    @souravkumarshaw7090 3 ปีที่แล้ว

    sir what is the time complexity for the above question?

  • @SumitSingh-ui4do
    @SumitSingh-ui4do 2 ปีที่แล้ว

    Mast solution sir❤️❤️

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      Glad you liked it.
      For better experience and well organised content explore nados.pepcoding.com

  • @246amishakumari7
    @246amishakumari7 3 ปีที่แล้ว

    you are amazing :)

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

    This ans is giving me a TLE . Its written in c++. please do read it
    string minWindow(string s, string t) {
    string ans="";
    unordered_map map2;
    for(auto &a: t)
    map2[a]++;
    int mct=0;
    int dmct=t.length();
    unordered_map map1;
    int i=-1;
    int j=-1;
    while(true)
    {
    bool f1=false;
    bool f2=false;
    while(i

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

      Beta koi edge case miss ho rh hoga, ek bari aache se dubara analyse kr k dekho. I'll even check it once again.

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

      sure sir i am checking it

    • @AdityaKumar-xd8mj
      @AdityaKumar-xd8mj 3 ปีที่แล้ว

      @@bighneshkumarpati8640 break conditon will be flag1==false and f2==false

    • @bighneshkumarpati8640
      @bighneshkumarpati8640 3 ปีที่แล้ว

      still its coming wrong

    • @kaushaljalan2928
      @kaushaljalan2928 3 ปีที่แล้ว

      class Solution {
      public:
      string minWindow(string s, string t) {
      string ans="";
      unordered_map map2;
      for(auto &a: t)
      map2[a]++;
      int mct=0;
      int dmct=t.length();
      unordered_map map1;
      int i=0,j=0;
      while(true)
      {
      bool f1=false;
      bool f2=false;
      while(i

  • @kancharlasrimannarayana7068
    @kancharlasrimannarayana7068 2 ปีที่แล้ว

    what is the time complexity?

  • @lokeshnegi5051
    @lokeshnegi5051 3 ปีที่แล้ว

    awesome work..

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thank you sir

  • @manavkumarjaiswal2734
    @manavkumarjaiswal2734 3 ปีที่แล้ว

    can anybody explain
    why are we start collecting from j+1 why not from j and starting j from zero instead of -1 don't you think there is mistake in this line

    • @mickyman753
      @mickyman753 3 ปีที่แล้ว

      doing this we get correct indexes of i and j for substring function
      you can just do j++ first and make current case susbtring as s1.susbtring(j,i+1)

  • @dewashishwankhede2478
    @dewashishwankhede2478 3 ปีที่แล้ว

    Amazing explanation

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad you think so!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      If you like my efforts, I request a review
      g.page/Pepcoding/review?rc

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

    java code - class Solution {
    public String minWindow(String s, String t) {
    HashMap map2 = new HashMap();
    for(int i = 0;i

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

    ❤❤