Leetcode - Remove Duplicate Letters (Python)

  Рет қаралды 4,957

Timothy H Chang

Timothy H Chang

Күн бұрын

Пікірлер: 19
@janmichaelaustria620
@janmichaelaustria620 4 жыл бұрын
it took me a while to figure out why answers for the example inputs were the way they were. nice video again Tim!
@timc3406
@timc3406 4 жыл бұрын
Me too, I thought the question was way too simple at first
@treyi1794
@treyi1794 3 жыл бұрын
shouldn't the condition be while (stack and stack[-1] > s[i] and lookup(stack[-1]) > i ) because its a subsequence and we are removing only duplicate letters?
@oleksiimartens9779
@oleksiimartens9779 Жыл бұрын
Time Complexity of this solution is O(n). We would need to remove 26 elements from the stack at most at each iteration which sets O(1) as the cost of an iteration
@HD-xn1br
@HD-xn1br 2 жыл бұрын
I like this solution! It seems like we don't actually need to use the seen set though? I removed it entirely and it still passes all test cases. We can just check if s[i] is in the stack.
@andreawong2935
@andreawong2935 11 ай бұрын
The operation "if s[i] in stack" is O(N) where N = len(stack), however, the operation "if s[i] in seen" is O(1), because seen is a set.
@themagickalmagickman
@themagickalmagickman Жыл бұрын
I feel silly for looking up the solution now, I shouldve been able to solve this. Need more determination
@andreawong2935
@andreawong2935 11 ай бұрын
Neet!! Thank you for sharing.
@sharifmansuri607
@sharifmansuri607 4 жыл бұрын
Thank you very much for this video. Sir I have a query, why we are not using sorted function. As following s='dcabde' l=sorted(set(s)) print (l)
@timc3406
@timc3406 4 жыл бұрын
I thought that at first too but we can't because the order of the string matters, we're not allowed to rearrange the letters, we can only remove them as is
@sajiinsta2026
@sajiinsta2026 2 жыл бұрын
how can i have just "a" in the output?i mean remove all two Consecutive letters e.g: input:hhoowaaaareyyoouu expected output:wre how can I do that?
@chessingh
@chessingh 2 жыл бұрын
this is a different problem, not explained in the video, btw what is the expected output for input:hhoowaaaareyyoouue? Then I can answer this better
@samarthasthana
@samarthasthana 4 жыл бұрын
Went the recursive way and regretted it :/
@timc3406
@timc3406 4 жыл бұрын
LOL that happens to me often
@vikasviki7490
@vikasviki7490 4 жыл бұрын
Waiting For this , thanks.
@timc3406
@timc3406 4 жыл бұрын
Thanks for waiting :)
@sniff4643
@sniff4643 4 жыл бұрын
subbed
@timc3406
@timc3406 4 жыл бұрын
Thanks!
REMOVE DUPLICATE LETTERS | LEETCODE 316 | PYTHON STACK SOLUTION
18:15
Inside Out 2: ENVY & DISGUST STOLE JOY's DRINKS!!
00:32
AnythingAlexia
Рет қаралды 9 МЛН
From Small To Giant Pop Corn #katebrush #funny #shorts
00:17
Kate Brush
Рет қаралды 70 МЛН
Leetcode - Buddy Strings (Python)
6:34
Timothy H Chang
Рет қаралды 2 М.
Remove Duplicate Letters | Leetcode #316
14:55
Techdose
Рет қаралды 26 М.
So You've Been Rejected from FAANG
5:56
Timothy H Chang
Рет қаралды 8 М.
316. Remove Duplicate Letters | Day 015 | Stack
13:36
Aryan Mittal
Рет қаралды 1,8 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 367 М.
Find Common Characters - Leetcode 1002 - Python
10:26
NeetCodeIO
Рет қаралды 12 М.