Find longest substring with K unique characters - Sliding Window Algorithm

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ย. 2024

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

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

    This is exactly what I was looking for. Amazing explanation
    Please make a playlist which is based on different coding patterns so that we can identify the pattern of problems and we can attempt it.
    Thank you

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

    Great explanation. Keep posting similar videos.

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

    Excellent explanation 🎉 Thanks 🙏

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

    super mam keep going for more number of coding questions🤩🤩🤩🤩

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

    in place of "While" we can just use a if statement for shrinking right? bcz there is no need of shrinking the window less than the already found longest sub array's length ..there by T.C reduces to O(N) from O(N)

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

    Great Explanation...
    Can you explain that why you've not used set in this problem, as we want to store unique characters & their count ? What is the advantage of using unordered map over a set ?

    • @codewithease-byvarsha
      @codewithease-byvarsha  ปีที่แล้ว

      well, fair enough, you use a set to store unique characters but how will you store the corresponding count of each character?

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

      @@codewithease-byvarsha Yes, I think that this is the advantage of using map over set is.
      A map will provide a built-in function to get the count of elements inside it (unlike a set).
      We can use a dictionary anyway.
      Thanks for your reply, btw

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

    Nice Explanation

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

    Hey, could you help me understand why is there a while loop on line 35 and not an if statement? Thank you for the video, was very useful. :)

    • @codewithease-byvarsha
      @codewithease-byvarsha  ปีที่แล้ว

      The while loop is used to handle cases where the number of unique characters in the current window exceeds the desired value (`k`). It dynamically adjusts the window size by incrementing the `start` index until the map size becomes equal to `k`. This ensures that the resulting substring will have exactly `k` unique characters.
      Hope this resolves your query.

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

      @@codewithease-byvarsha Hey, thank you for the reply and the explanation. I thought so too but I couldn't think of a test case that wouldn't work with just the if statement. In case you have one in mind please let me know, thank you anyway. :)

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

    If we want to print the characters of that string how will modify the code

    • @codewithease-byvarsha
      @codewithease-byvarsha  ปีที่แล้ว +1

      Track the ith pointer as startIndex
      if (map.size() == k && j - i + 1 > maxLen) {
      maxLen = j - i + 1;
      startIndex = i;
      }
      and use substring method on start & end Index(start+max)

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

      Thanks@@codewithease-byvarsha

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

    String s = "abc.b.cc";
    find the longest substring length without '.'(dot).....Using java ...ma'am @Code With Ease please provide the code

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

    Thanks u for the solution

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

    TBH, I'm still confused.

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

    great di di

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

    didi please please make a detailed vedio on variable size sliding window it would of great help

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

      hlo didi first really thankyou for your great explanation but this code is not able to clear all test case in gfg
      I have coded in c++

    • @codewithease-byvarsha
      @codewithease-byvarsha  2 ปีที่แล้ว +1

      Sure, we will definitely try to create one on sliding window.

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

    please use hindi if possible