Тёмный

L6. Longest Substring With At Most K Distinct Characters | 2 Pointers and Sliding Window Playlist 

take U forward
Подписаться 597 тыс.
Просмотров 21 тыс.
50% 1

Notes/Codes/Problem links under step 10 of A2Z DSA Course: takeuforward.org/strivers-a2z...
Entire playlist: • Two Pointer and Slidin...
Follow us on our other social media handles: linktr.ee/takeuforward

Опубликовано:

 

30 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 55   
@FutureForge-ir7xc
@FutureForge-ir7xc 2 месяца назад
Thank you so much Striver!!!!
@rudrajitgupta3688
@rudrajitgupta3688 3 месяца назад
Understood Striver. Was able to reuse the same code that was implemented in previous lecture before starting to watch the solution. Thank you again for such a great explanation
@txbankush4601
@txbankush4601 15 дней назад
can u provide the full code. I am getting some of my testcases failed.
@adarshshankarrai9912
@adarshshankarrai9912 13 дней назад
@@txbankush4601 int n,k; cin >> n >> k; string s; cin >> s; int l = 0, r = 0, maxlen = 0; mapmp; while(r < n) { mp[s[r]]++; if(mp.size() > k){ while(mp.size() > k){ mp[s[l]]--; if(mp[s[l]] == 0){ mp.erase(s[l]); } l++; } } if(mp.size()
@SHARNAMKANSAL
@SHARNAMKANSAL 6 дней назад
@@txbankush4601 int l=0,r=0,maxi=-1; unordered_mapmpp; while(rk) { mpp[s[l]]--; if(mpp[s[l]]==0)mpp.erase(s[l]); l++; } if(mpp.size()==k) { maxi=max(maxi,r-l+1); } r++; } return maxi;
@shashankshekhar1713
@shashankshekhar1713 4 дня назад
@@txbankush4601 for previous problem int totalFruits(int N, vector &arr) { int left = 0, right = 0, maxLength = 0; unordered_map map; while (right < N) { map[arr[right]]++; if (map.size() > 2) { map[arr[left]]--; if (map[arr[left]] == 0) { map.erase(arr[left]); } left++; } if(map.size()
@harpreetnarwal6250
@harpreetnarwal6250 2 месяца назад
Thank you so much brother!! was able to do this before watching the video all thank to you!!
@tejasjaulkar9658
@tejasjaulkar9658 2 месяца назад
lot of love from us striver ......... thank u so muchhhhh
@gauravlandge3356
@gauravlandge3356 2 месяца назад
I used to struggle a lot with sliding window Questions Thanks to u and your playlist because of which i am able to solve this type of Questions. Thankyou very much.
@AkshitChaudhary-vx8iw
@AkshitChaudhary-vx8iw 3 месяца назад
thankyou so much Striver. i solved this question at my own just because of your previous lectures. you are amazing😍
@shwetanshusinha2690
@shwetanshusinha2690 3 месяца назад
Thank you sir for such an important series
@subee128
@subee128 3 месяца назад
Thank you very much
@codeman3828
@codeman3828 2 месяца назад
Understood. Thanks
@_sf_editz1870
@_sf_editz1870 3 месяца назад
Solved this 💕💕
@prateekshrivastava2802
@prateekshrivastava2802 27 дней назад
Previous question is same to this one !!
@augustinradjou3909
@augustinradjou3909 3 месяца назад
I solved the question 😅 and then watching to get more idea ...little bit change of previous question....tryit guys then see the video❤
@LearnWithMe7777
@LearnWithMe7777 19 дней назад
Similar as previous in last lec Understood ❤
@PIYUSHTAILORstillalive
@PIYUSHTAILORstillalive 2 месяца назад
Could we use use queue to store char and the index of that character? The latest one and when size increases to 3 then we drop the front and take the latest index. Update the length and r keep on going. I just don't want that while loop running to find our l.
@augustinradjou3909
@augustinradjou3909 3 месяца назад
Its okay to opt with map it is much more intuitive...i feel but yeah vector is more good ofcourse😅
@varenyabarve9391
@varenyabarve9391 Месяц назад
We wont able to access this question, it's saying to view this question you must subscribe to premium 😢 . Now how to do that ?
@anandraj3995
@anandraj3995 29 дней назад
do it on coding ninja
@saatvikmangal7994
@saatvikmangal7994 28 дней назад
@@anandraj3995 tysm bro
@prateekshrivastava2802
@prateekshrivastava2802 27 дней назад
Gfg me same question h
@shashankshekhar1713
@shashankshekhar1713 4 дня назад
@@prateekshrivastava2802 link?
@TheK_Fam
@TheK_Fam 2 месяца назад
One note here is that if the answer is not possible you would need to only update the max_len when len(ch_map) == k and initiate the max_len to be -1
@bunnysahith4810
@bunnysahith4810 2 месяца назад
similar to approach in l5
@kartik.garg127__
@kartik.garg127__ 3 месяца назад
Sir i am following ur course should i start with stack and queues(acc. To other yt channel) or start linklist i had completed till binnary search ❤❤❤
@samagraagrawal5333
@samagraagrawal5333 3 месяца назад
Link list se start Karo. Stack and queue ke implementation mein link list ka use aayega
@rlm3227
@rlm3227 20 дней назад
understood
@VardhanagariBhupeshReddy
@VardhanagariBhupeshReddy 2 месяца назад
Why was it O(256) space for brute force? because size is k distinct right? like as soon as size becomes k+1, we break. i didn't understand why so much extra space is being taken
@lakshsinghania
@lakshsinghania Месяц назад
suppose the len of string is 256 containing all different characters and k = 256 then space will be O(256) he is writing everything in worst case thats like upper bound
@angeldeveloper
@angeldeveloper 3 месяца назад
🎉❤
@devvikramsingh7785
@devvikramsingh7785 3 месяца назад
it's better to use Vector rather than Hashmap
@30sunique78
@30sunique78 3 месяца назад
Why ?
@samagraagrawal5333
@samagraagrawal5333 3 месяца назад
​@@30sunique78 Hashmap works in logarithmic time , while vector/array/list in constant time Although if you are working in c++ there is also unordered map which works in constant time but still even then it is prefered to work with vectors as the constants involved with vector are better than hash maps
@harshi993
@harshi993 2 месяца назад
O(1) time complexity and only O(26) space
@AJK-a2j00k4
@AJK-a2j00k4 2 месяца назад
Hey, I didn't understand one thing, that he mentions extra TC O(log 256) where is this coming from? plus he is saying Space complexity as O(256) but there are only 26 alphabets right, then how is it 256 instead of 26? can someone plzz clarify this with detailed explanation or some video link/ references to understand this! Thank you
@abhay3545
@abhay3545 2 месяца назад
There are 256 characters in any programming language, 26 (A-Z)+26(A-Z)+ special characters. The problem string can have any of the characters of 256.
@AJK-a2j00k4
@AJK-a2j00k4 2 месяца назад
@@abhay3545 ohh thnx
@shreyaagarwal4320
@shreyaagarwal4320 2 месяца назад
why is the TC roughly O(2n) ? it is while inside while right, so it should be O(n^2)
@youcanyouwill2004
@youcanyouwill2004 2 месяца назад
n^2 happens only when for every constant j -> i runs till end, but here overall i runs only once and j also runs only once throughout the program. watch previous lecture striver has explained it
@Dharmik_Vibes
@Dharmik_Vibes 8 дней назад
Same as Fruit In basket
@user-gk4zy6bk7l
@user-gk4zy6bk7l Месяц назад
god
@ajithshetty1684
@ajithshetty1684 Месяц назад
what happens when string is "AABABBA" Actual output will be 5 but current code will give 7, here k=2 means at max 2 times A to B conversion or vice versa can be done as per leetcode
@ajithshetty1684
@ajithshetty1684 Месяц назад
Inputs & expected output from leetcode 1) Input: s = "ABAB", k = 2 Output: 4 Explanation: Replace the two 'A's with two 'B's or vice versa. 2) Input: s = "AABABBA", k = 1 Output: 4 Explanation: Replace the one 'A' in the middle with 'B' and form "AABBBBA". The substring "BBBB" has the longest repeating letters, which is 4. There may exists other ways to achieve this answer too.
@ajithshetty1684
@ajithshetty1684 Месяц назад
But if this question is not linked to leetcode and the expectation is to find longest substring of k dinstinct characters then solution is perfect
@txbankush4601
@txbankush4601 15 дней назад
someone pls provide the full code. I am getting some of my testcases failed.
@ManishKumar-dk8hl
@ManishKumar-dk8hl 3 месяца назад
import java.util.HashMap; public class Solution { public static int kDistinctChars(int k, String str) { int l=0; int r=0; int maxlen=0; HashMapmpp=new HashMap(); while(r
@aniketsingh5516
@aniketsingh5516 2 месяца назад
not working
@ibrahimalikhan3539
@ibrahimalikhan3539 2 месяца назад
@@aniketsingh5516 Correct this condition if(mpp.size() == k )
@prathameshlendghar827
@prathameshlendghar827 28 дней назад
Question in sheet is not correctly mapped with the video It expects to interchange any k char and by doing so find the longest string with same character and in the video it is changing all occurances of a distinct characters and for all instance of k different character.
@Sahilsharma-sk5vr
@Sahilsharma-sk5vr 8 дней назад
right
@giridharanpasupathi
@giridharanpasupathi 2 месяца назад
🙄🙄🙄🙄 Am i the only one know that the L5 and L6 are same question
@spotshot7023
@spotshot7023 2 месяца назад
Yes, it's same
@RaghavN-rd5zw
@RaghavN-rd5zw 2 месяца назад
Thank you so much Striver!!!
Далее
HUMAN BASKETBALL! 👀🏀🤣 | Triple Charm #Shorts
00:15
Как выжить на 1000 рублей?
13:01
Просмотров 685 тыс.
Coding Interviews Be Like
5:31
Просмотров 6 млн
WHY did this C++ code FAIL?
38:10
Просмотров 187 тыс.
10 Math Concepts for Programmers
9:32
Просмотров 1,8 млн
Erdős-Woods Numbers - Numberphile
14:12
Просмотров 73 тыс.
How I would learn Leetcode if I could start over
18:03
Просмотров 279 тыс.
HUMAN BASKETBALL! 👀🏀🤣 | Triple Charm #Shorts
00:15