Very intelligent explaination... Not my cup of tea to understand. anyway thanks.
@NareshGupta2 жыл бұрын
hehe - learn practice and apply is the key to success.
@InsaneRG41722 жыл бұрын
whats the space complexity and time complexity?
@imanhn2 жыл бұрын
Nice 🙏
@midasama31242 жыл бұрын
Time complexity is O(N) indeed. While loop while traversing string is 26*N is the worst case scenario.
@protyaybanerjee50513 жыл бұрын
Nice explanation
@NareshGupta3 жыл бұрын
Keep watching
@deepankerchaudhary71872 жыл бұрын
You earned a subscriber good explanation
@NareshGupta2 жыл бұрын
Thanks and welcome
@muskangupta25452 жыл бұрын
Thanks for this wonderful explanation
@NareshGupta2 жыл бұрын
Thanks
@monkeytrollhunter4 жыл бұрын
I spent an hour and I couldn't get it. so I am here. Thank you
@NareshGupta4 жыл бұрын
This problem is little tricky unless you have solved similar problem tuff to come up with solution. Try if not - leetcode.com/problems/remove-k-digits/
@ManishKumar-eg7ke3 жыл бұрын
nice one
@NareshGupta3 жыл бұрын
Thanks
@heisenberg18443 жыл бұрын
Can you please tell how did you conclude you need a while loop and not a simple if check (just remove the top)?
@neerajkorde Жыл бұрын
you can remove all the prev characters as long as there are more coming ahead(countmap >= 0). Also when 'larger' letters come later, they make a lexicografically smaller word.
@duongphan2192 жыл бұрын
So easy to understand. Thanks
@NareshGupta2 жыл бұрын
Thanks
@davidjunghan914 жыл бұрын
I participate in leetcode daily quiz. Sometimes I can solve the problem myself. But I usually fail to pass and looking for solutions. Does solutions helps to improve solving skills? When try a new problem, I encounter the same loop..
@NareshGupta4 жыл бұрын
Learn and Practice and try to relates problem if you can relate already solved ones. Also, before looking solution try hard and atleast come up with brute force solutions even if TLE in leetcode thats fine. Once you get working solution you can review and try to think if you can improve time. Also, Sometime some problems are tricky which will not easily to come up with solutions so you have to look solution and learn. If you fresh beginner or doing ds-algo after long time - Don't feel disproportionate just keep practice and learn. LeetCode daily challenge problems are randomly selected so any day any topic problem - if you haven't read that topic and solve some standard problem then its tuff so start learning topic-wise parallel.
@davidjunghan914 жыл бұрын
Thank you for replying. I’ll try the standard problems in high priority
@NareshGupta4 жыл бұрын
Either follow leetcode explore or interviewbit ds-algo section.
@rajatgarg21664 жыл бұрын
I'm able to understand your approach. Thanks
@NareshGupta4 жыл бұрын
You are welcome!
@nayankhuman10434 жыл бұрын
very good explanation sir !!!
@NareshGupta4 жыл бұрын
Thanks and welcome
@VishalSharma-hq5ti3 жыл бұрын
We could do it without stack also rt?
@satishshingade85143 жыл бұрын
thanks for the solution the problem was really tricky and it was almost looking like dp ..
@willturner34403 жыл бұрын
Dp? Where you find here dp
@siddharthb22263 жыл бұрын
@@willturner3440 lavday, he said it looks like dp. Didnt say it was dp
@hodex57633 жыл бұрын
What do we mean by lexicographical order
@NareshGupta3 жыл бұрын
Check the wikipedia you will get good idea - en.wikipedia.org/wiki/Lexicographic_order In general it is sorted order in aphabet. "abc" is lexicographically smaless than "bac".
@hodex57633 жыл бұрын
@@NareshGupta then why not abcd but acbd I searched on Google didn't understood that's why came here
@NareshGupta3 жыл бұрын
@@hodex5763 If you taking about the problem example Input: s = "cbacdcbc" Output: "acdb" Here along with lexicographical smallest we have to keep single presence of exiting character and maintain the relative orders. "cbacdcbc" - we have 4 different characters we can remove first c, b as we have more occurrence of c, b later in string with we will get a in starting that will give us start of smallest lexi string.
@justshanky30123 жыл бұрын
How is the time complexity O(n) when we are using a stack? That while loop might also take some time right?
@ayushagrawal64733 жыл бұрын
Each character from string is whether added or removed only once. That means each char is traversed only twice. Which makes it the complexity of O(2*n) ~ O(n).
@praveenj31124 жыл бұрын
We can add unique character in the stack and sort it . Is this work ?
@NareshGupta4 жыл бұрын
No, check second example if you sort unique chars abcd will be answer which is not expected.
@praveenj31124 жыл бұрын
@@NareshGupta yes I got it . Thanks
@PritamKumar-mr5dv3 жыл бұрын
cool
@paragroy53593 жыл бұрын
Thanks for the video nice explanation....according to me this is a tricky problem tough to solve in the contest if didn't solved such question before
@NareshGupta3 жыл бұрын
Thanks. Yes, correct that is the reason keep doing practice.
@dipteshsil92994 жыл бұрын
Hi Naresh, I did not understand how your logic will work for an input like "cba". If I am popping 'c' on encountering 'b' and similarly 'b' on facing 'a', then my stack contains only 'a' after traversing the string.
@NareshGupta4 жыл бұрын
You missed the part of lastIndex - this array is used to the purpose of tracking whether if we have same character in string later then only pop from stack if not then don't.
@willturner34403 жыл бұрын
Please make playlist on placement preparation
@NareshGupta3 жыл бұрын
Can you help me to share collection of problems
@willturner34403 жыл бұрын
@@NareshGupta yes, share your mail. Then I'll..
@adarshsharmanit3563 жыл бұрын
Appreciated Brother !! THanks , Liked ur solution !!
@NareshGupta3 жыл бұрын
Always welcome
@davidjunghan914 жыл бұрын
This time it's not easy to understand. But I'll try more
@NareshGupta4 жыл бұрын
Keep trying unless you clearly understand
@tieqi56234 жыл бұрын
Watch your video everyday, Really appreciate it. One little suggestion is do better hand writing when you draw the diagram :)
@NareshGupta4 жыл бұрын
Noted
@vedantagarwal224 жыл бұрын
You do very good work sir, thankyou !
@NareshGupta4 жыл бұрын
Thanks and You are welcome
@elliotho30152 жыл бұрын
really helpful, thank you!
@Ice-27064 жыл бұрын
it was a nice and easy explanation... good job !!
@NareshGupta4 жыл бұрын
Thanks, Glad it helped!
@neerajkorde Жыл бұрын
bhai teri handwriting doctor se bhi advanced hai
@bhargavsai24493 жыл бұрын
tu
@deepakjaiswal17224 жыл бұрын
Giving runtime error
@NareshGupta4 жыл бұрын
Why? did you found root cause? Or compare with my code in github - github.com/naresh1406/youtube/blob/master/src/main/cp/leetcode/october/Day_11_316_Remove_Duplicate_Letters.java
@rhythmjayee97074 жыл бұрын
very good explanation. Thanks a lot!! keep the good work.
@NareshGupta4 жыл бұрын
Thanks. You are welcome!
@priyanshu.tiwari4 жыл бұрын
Very poorly explained. Please don't make videos like these.