it took me a while to figure out why answers for the example inputs were the way they were. nice video again Tim!
@timc34064 жыл бұрын
Me too, I thought the question was way too simple at first
@treyi17943 жыл бұрын
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 Жыл бұрын
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-xn1br2 жыл бұрын
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.
@andreawong293511 ай бұрын
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 Жыл бұрын
I feel silly for looking up the solution now, I shouldve been able to solve this. Need more determination
@andreawong293511 ай бұрын
Neet!! Thank you for sharing.
@sharifmansuri6074 жыл бұрын
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)
@timc34064 жыл бұрын
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
@sajiinsta20262 жыл бұрын
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?
@chessingh2 жыл бұрын
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