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
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)
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 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
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.
@@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. :)
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)
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
Great explanation. Keep posting similar videos.
Excellent explanation 🎉 Thanks 🙏
super mam keep going for more number of coding questions🤩🤩🤩🤩
Thanks, stay tuned for more videos like this!
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)
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 ?
well, fair enough, you use a set to store unique characters but how will you store the corresponding count of each character?
@@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
Nice Explanation
Thanks and welcome . Do spread the word with your peers!
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. :)
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.
@@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. :)
If we want to print the characters of that string how will modify the code
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)
Thanks@@codewithease-byvarsha
String s = "abc.b.cc";
find the longest substring length without '.'(dot).....Using java ...ma'am @Code With Ease please provide the code
Thanks u for the solution
Glad you enjoyed it .Do subscribe & spread the word.
TBH, I'm still confused.
great di di
didi please please make a detailed vedio on variable size sliding window it would of great help
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++
Sure, we will definitely try to create one on sliding window.
please use hindi if possible