Minimum Window Substring - Two pointers #1 | Coding Interview

Поделиться
HTML-код
  • Опубликовано: 20 янв 2025

Комментарии • 24

  • @alperozdamar517
    @alperozdamar517 4 года назад +9

    This is a great explanation. I'm so surprised that nobody wrote any comment about your solution and explanation. Thank you for a clear and easy solution.

    • @InvolveInInnovation
      @InvolveInInnovation  4 года назад

      Thanks for your kind words! Please share it with your friends if you find this video helpful.

  • @Demigod23393
    @Demigod23393 4 года назад +1

    The second while loop should be while(l

  • @arunitbaidya6118
    @arunitbaidya6118 4 года назад +2

    The most simple and clear solution I found!

  • @Deep-zk6dl
    @Deep-zk6dl 4 года назад +1

    This is the best explaination for this problem on youtube. Thank you so much 😊

  • @purnimavijaya1231
    @purnimavijaya1231 4 года назад

    The best explanation I found for this problem!

  • @shaikhirfan2799
    @shaikhirfan2799 2 года назад

    I am getting error in if condition it's asking that cannot find variable (invalue()) this is showing me cannot find

  • @amanr11314
    @amanr11314 4 года назад +1

    Thanks man you saved me lots of time

  • @anilkishorereddy9246
    @anilkishorereddy9246 4 года назад +1

    Great explaination

  • @GAURAVGUPTA-zu2bu
    @GAURAVGUPTA-zu2bu 4 года назад +1

    What is the need of if statement res[0]==-1 || res[0]>r-l+1 in 2nd while loop.I didn't get?

    • @InvolveInInnovation
      @InvolveInInnovation  4 года назад +1

      That is check and replace the result only if result is not already found (res[0]==-1, this is what we initialized), second is to check if the newly found one is minimum then the existing one(res[0]>r-l+1).

  • @iark1
    @iark1 4 года назад

    Very nice explanation! Thanks a lot!

  • @anushacheedella2291
    @anushacheedella2291 3 года назад

    Very great explanation 👌

  • @vishnukhanna9246
    @vishnukhanna9246 3 года назад

    Best explanation

  • @rodrickedwards2759
    @rodrickedwards2759 4 года назад

    Great explanation. Thanks.

  • @animeshsaxena3626
    @animeshsaxena3626 4 года назад

    Simplified approach ! :)

  • @shaikhirfan2799
    @shaikhirfan2799 2 года назад

    I am doing in normal editor with main method

  • @matpoliquin
    @matpoliquin 2 года назад

    Well explained and concise! Thank you!

  • @mayanksikarwal8431
    @mayanksikarwal8431 4 года назад

    nice explanation bro.

  • @kaushalrajsinghbhati5076
    @kaushalrajsinghbhati5076 4 года назад +1

    Good explanation. Pronunciation and tone needs a bit of improvement btw.

  • @premchandru05
    @premchandru05 4 года назад

    s = "aa" and t= "aa", this test case is not working

    • @premchandru05
      @premchandru05 4 года назад +1

      Please check my working solution and please correct me if I am wrong.
      class Solution {
      public String minWindow(String s, String t) {
      if(s ==null || t==null || s.length()==0 || t.length() == 0 || s.length() < t.length())
      return "";
      Map window = new HashMap();
      for(char c:t.toCharArray())
      window.put(c,window.getOrDefault(c,0)+1);
      Map minWindow = new HashMap();
      int l =0;
      int r =0;
      int expe = 0;
      int real = t.length();
      int[] output = {-1,0,0};
      while(r < s.length()){
      char c = s.charAt(r);
      minWindow.put(c,minWindow.getOrDefault(c, 0)+1);
      if(window.containsKey(c) && minWindow.get(c).intValue() (r-l)+1){
      output[0] = (r-l)+1;
      output[1] = l;
      output[2] = r;
      }
      char cc = s.charAt(l);
      minWindow.put(cc,minWindow.getOrDefault(cc, 0)-1);
      if(window.containsKey(cc) && minWindow.get(cc).intValue() < window.get(cc).intValue()){
      expe--;
      }
      l++;
      }
      r++;
      }
      return (output[0]==-1?"":s.substring(output[1],output[2]+1));
      }
      }

    • @maidul13
      @maidul13 4 года назад

      Because this solution only works if t only contains unique chars.

  • @RiteshSingh-ru1sk
    @RiteshSingh-ru1sk 4 года назад +1

    The simplest explaination u will find on internet..