Find longest substring with K unique characters - Sliding Window Algorithm

  Рет қаралды 8,183

Code With Ease - By Varsha

Code With Ease - By Varsha

Күн бұрын

Пікірлер: 26
@vipinthakur8355
@vipinthakur8355 9 ай бұрын
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 2 жыл бұрын
super mam keep going for more number of coding questions🤩🤩🤩🤩
@codewithease-byvarsha
@codewithease-byvarsha Жыл бұрын
Thanks, stay tuned for more videos like this!
@manusklm1161
@manusklm1161 5 ай бұрын
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)
@imPriyansh77
@imPriyansh77 Жыл бұрын
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?
@imPriyansh77
@imPriyansh77 Жыл бұрын
@@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
@codewithease-byvarsha
@codewithease-byvarsha Жыл бұрын
Thanks and welcome . Do spread the word with your peers!
@bharanitharan1220
@bharanitharan1220 Жыл бұрын
If we want to print the characters of that string how will modify the code
@codewithease-byvarsha
@codewithease-byvarsha Жыл бұрын
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)
@imPriyansh77
@imPriyansh77 Жыл бұрын
Thanks@@codewithease-byvarsha
@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. :)
@mckenziepictures
@mckenziepictures 7 ай бұрын
TBH, I'm still confused.
@Alok_Roy
@Alok_Roy 4 ай бұрын
String s = "abc.b.cc"; find the longest substring length without '.'(dot).....Using java ...ma'am @Code With Ease please provide the code
@udaytewary3809
@udaytewary3809 2 жыл бұрын
didi please please make a detailed vedio on variable size sliding window it would of great help
@udaytewary3809
@udaytewary3809 2 жыл бұрын
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 жыл бұрын
Sure, we will definitely try to create one on sliding window.
@Omneeshkushwah9695
@Omneeshkushwah9695 Жыл бұрын
Thanks u for the solution
@codewithease-byvarsha
@codewithease-byvarsha Жыл бұрын
Glad you enjoyed it .Do subscribe & spread the word.
@priyanshkashyap2993
@priyanshkashyap2993 Жыл бұрын
great di di
@puneetsrivastava9848
@puneetsrivastava9848 4 ай бұрын
please use hindi if possible
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 301 М.
Sorting Algorithms Explained Visually
9:01
Beyond Fireship
Рет қаралды 560 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН