Remove All Adjacent Duplicates in String II - Leetcode 1209 - Python

  Рет қаралды 49,776

NeetCode

NeetCode

Күн бұрын

Пікірлер: 61
@しげお-i1l
@しげお-i1l 2 жыл бұрын
Just got the news today that I'll be getting an offer from Amazon. Thank you so much for all the effort you continue to put in this channel! It really changes lives!
@NeetCode
@NeetCode 2 жыл бұрын
That's so great!! Congratulations 🎉🎉🎉
@Mamtagoyal27
@Mamtagoyal27 2 жыл бұрын
Can you please tell us about your preparation strategy in the discord channel for Neetcode?
@ostenloo1981
@ostenloo1981 2 жыл бұрын
Your vids are great, it's helped me progress to the point I can solve most mediums! I just solved this one before you uploaded (it is the daily challenge).
@enriquem9213
@enriquem9213 2 жыл бұрын
How long have you been practicing for?
@the_real_briel
@the_real_briel 2 жыл бұрын
I love you neet code 🤗 these videos are always a fantastic reference for when I am confused af. And huge respect for doing so much work for me by creating that website for me to track my blind 75 progress and you didn't even throw ads on it! I've got my first faang interview in just under two weeks and if I get it I attribute it 100% to your fantastic creations! Keep up the great work! I'm sure you will make it super far if you keep working as hard as you do!
@masternobody1896
@masternobody1896 2 жыл бұрын
more code nice
@mariagu9967
@mariagu9967 2 жыл бұрын
Wow, every time I watch Neetcode, I feel my brain refreshed! Thank you so much!
@alexl2512
@alexl2512 Жыл бұрын
The idea of combing value and count together is brilliant.🎉
@Nerdimo
@Nerdimo 2 жыл бұрын
Oh my gosh, this is incredibly intuitive. Push out what you can I love seeing these man!
@symbol767
@symbol767 2 жыл бұрын
Nice explanation, I solved this on my own with a stack but you did it much cleaner and in a better way, thank you
@bmwdude38
@bmwdude38 2 жыл бұрын
Appending to a string in python is an O(n+m) operation. The last loop looks O(n**2) to me.
@TheQuancy
@TheQuancy 2 жыл бұрын
I feel a little accomplished if I were to solve the problem after the coding explanation without looking at your solution. Now all I need is to find the solution without looking at the explanation.
@vdyb745
@vdyb745 2 жыл бұрын
Automatic like even before watching the entire video. Insane right ? Nah ... just complete confidence in the quality of your content. Hope you are feeling better now !!!
@ChenAubrey
@ChenAubrey 2 жыл бұрын
Hi NeetCode, Thank you for this great video. But speaking of final part of you solution. In python string is immutable. So every time you use res += (char * count). It will not simply add char behind original string. In fact it will create a new string object to achieve this += statement. My question will be would it be more efficient to use a list to store all char by appending them and return "".join(res)?
@blackda5686
@blackda5686 2 жыл бұрын
Totally agree. I used ''.join([letter * count for letter, count in stack])
@gianniprocida3332
@gianniprocida3332 2 жыл бұрын
The best educational KZbin channel
@ksawerylejczak6975
@ksawerylejczak6975 2 жыл бұрын
I think that part when you creating res can be simplified to: return ''.join([char * count for char, count in stack])
@andrewpaul6251
@andrewpaul6251 Жыл бұрын
this is what i did. Makes it more efficient as well
@infinitygod5379
@infinitygod5379 2 жыл бұрын
I thought of using stack, slowing building it one at a time keeping a top pointer and a start pointer(Star pointer and top are different only if there exists a continuous sequence of same chars) and use those pointers to remove continuous chars of Len k
@omkarbhale442
@omkarbhale442 Жыл бұрын
As soon as I saw the question, I knew it was similar to parenthesis problem. I wonder why this is medium difficulty, since it's very very similar to prenthesis problem.
@Odinh
@Odinh 2 жыл бұрын
I am not sure if this would be a valid test dataset: abcbbccaa. If i am correct your explanation says that it would return "" in accordance of the stack a:3 b:3 c:3 though you can clearly see this string would return itself as leftovers. How would we take this datapoint in account?
@Narblets
@Narblets 2 жыл бұрын
The stack is only tracking letters contiguously. For the string you posted the stack would look like: a:2 c:2 b:2 c:1 b:1 a:1
@chetansn6030
@chetansn6030 2 жыл бұрын
Could you pls explain on how to do it if instead of adjacent same character, we have to remove if a pattern is repeated Eg. Input - abcabcabcd Output - abcd Thanks
@halahmilksheikh
@halahmilksheikh 2 жыл бұрын
Hope you feel better soon
@____r72
@____r72 2 жыл бұрын
iA
@__--__--__--__--
@__--__--__--__-- 2 жыл бұрын
I wish you learn Javascript and do the coding on Javascript :( Would make a lot of people happy.
@iamnoob7593
@iamnoob7593 4 ай бұрын
Amazing explanation
@samyuktaneeraj4026
@samyuktaneeraj4026 Ай бұрын
But what about a string like ababa and k = 2? If we follow this method, then you will just end up deleting the entire string
@mohithadiyal6083
@mohithadiyal6083 2 жыл бұрын
Your explanation is simply amazing 😁
@Justice4x
@Justice4x 2 жыл бұрын
always content as always neetcode! just a question though. wont you get in trouble if you make coding interview vids? i recall techlead got into trouble cuz of his youtube content with google
@sharan10salian
@sharan10salian 2 жыл бұрын
Requesting - 1910. Remove All Occurrences of a Substring
@__agpatel__
@__agpatel__ 2 жыл бұрын
Your videos are awsome...Great Work...
@eyosiasbitsu4919
@eyosiasbitsu4919 2 жыл бұрын
shout out to all loyal subscribers who were here before neet got into google👏🏿👏🏿👏🏿👏🏿👏🏿
@david-yan-yt
@david-yan-yt 2 жыл бұрын
Amazing video! Very clear, thank you
@nishantingle1438
@nishantingle1438 2 жыл бұрын
I come here to check the top LC question name and try to solve them myself in 40 mins. And see solution if I cannot.
@nathamuni9435
@nathamuni9435 2 жыл бұрын
can we use hashmap keeping the chars as keys and values to n.o of occurences then remove all values as 3
@tanaysaxena8850
@tanaysaxena8850 2 жыл бұрын
Hashmap will not be able to check for “consecutive” K occurrences.
@edwardteach2
@edwardteach2 Ай бұрын
U an Adjacent Duplicates in String II God
@numberonep5404
@numberonep5404 2 жыл бұрын
not gonna lie, u were missed
@VasheshJ
@VasheshJ 2 жыл бұрын
class Solution: def removeDuplicates(self, s: str, k: int) -> str: i = 0 length = len(s) - 1 while i < length: if s[i:i+k] == s[i]*k: s = s[:i] + s[i+k:] i -= k length -= k i += 1 if i < 0: i = 0 return s This was my solution which passed all test cases. I was wondering what is the time complexity of this solution?? I think it is O(n^2) but could anyone give an example of the worst case when that would be correct?
@birdbeakbeardneck3617
@birdbeakbeardneck3617 2 жыл бұрын
your iterating about n times if searching in a string that its length decreases each time(given that u dont search from the start of the string), its like printing a pyramid of characters(each time you print a shorter string, if we condider printing 1 char O(1)) so still O(n^2)
@birdbeakbeardneck3617
@birdbeakbeardneck3617 2 жыл бұрын
also am new to the field but i dont know what you mean by wirst cade example, arent those of n solutions supposed to give us an idea about the performance and time of execution around infinity?
@birdbeakbeardneck3617
@birdbeakbeardneck3617 2 жыл бұрын
btw i thought of the exact same solution, and i forgot that k can get pretty big(took k as 3)so didint bother making a stack since the index needs only to go back 2 characters.
@VasheshJ
@VasheshJ 2 жыл бұрын
@@birdbeakbeardneck3617 ohh thanks understood. isn’t it very similar to bubble sort’s time complexity?
@birdbeakbeardneck3617
@birdbeakbeardneck3617 2 жыл бұрын
@@VasheshJ yes
@qingyachen1635
@qingyachen1635 2 жыл бұрын
I think consecutive numbers are for example: 1, 2, 3, 4, 5, 6, so maybe 333 has a better name to call it?
@maliahrajan2595
@maliahrajan2595 2 жыл бұрын
You are amazing!!
@vixguy
@vixguy Жыл бұрын
so satisfying!
@prathapreddyp
@prathapreddyp 2 жыл бұрын
I believe the last line should be res = (char * count) + res since stack stores the chars in reverse order
@mfizt2537
@mfizt2537 2 жыл бұрын
no lol
@1vader
@1vader 2 жыл бұрын
You can see in the video that it passed the tests. If you poped characters from the stack you'd get them in reverse order but he just traverses the stack from the "bottom".
@pankaj7979
@pankaj7979 2 жыл бұрын
If only u used c++. But anyways thanks for this amazing explanation
@vamsikumar295
@vamsikumar295 Жыл бұрын
Hi Your code is failing for K=1
@kwakukusi4094
@kwakukusi4094 2 жыл бұрын
amazing !!!!
@krateskim4169
@krateskim4169 2 жыл бұрын
beautiful
@eyosiasbitsu4919
@eyosiasbitsu4919 2 жыл бұрын
neet as always!
@adityagoswami6881
@adityagoswami6881 2 жыл бұрын
this piece of code is giving Memory limit exceeded ,Can anyone please review this code class Solution { public: string removeDuplicates(string s, int k) { vectorst; for(int i=0;i
@dalilou
@dalilou 2 жыл бұрын
Thanks! I didn't really know about stacks before but they seem really useful. Also, thanks to you, I've managed to get the runtime down to 99ms by using a one-dimensional array as stack and other little things.
@shitluna50kgonedogegogogo87
@shitluna50kgonedogegogogo87 10 ай бұрын
def remove_suplicates(string,k,last): ans = '' i = 0 while i
132 Pattern - Leetcode 456 - Python
12:02
NeetCode
Рет қаралды 64 М.
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 111 МЛН
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 12 МЛН
Ice Cream or Surprise Trip Around the World?
00:31
Hungry FAM
Рет қаралды 21 МЛН
5G: Upgrade or Uncertainty?
14:45
Skeptoid Media
Рет қаралды 12
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 148 М.
Top 8 Data Structures for Coding Interviews
14:00
NeetCode
Рет қаралды 161 М.
REMOVE DUPLICATE LETTERS | LEETCODE 316 | PYTHON STACK SOLUTION
18:15
Cracking FAANG
Рет қаралды 2,4 М.
Edit Distance - Dynamic Programming - Leetcode 72 - Python
21:00
Shortest Bridge - Leetcode 934 - Python
14:51
NeetCode
Рет қаралды 39 М.
CONSTRUCT BINARY TREE FROM STRING | LEETCODE 536 | PYTHON STACK SOLUTION
16:42
Remove adjacent duplicates in a string
8:27
Techdose
Рет қаралды 53 М.
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 111 МЛН