remove duplicate letters | leetcode 316 | smallest subsequence of distinct characters| leetcode 1081

  Рет қаралды 26,010

Naresh Gupta

Naresh Gupta

Күн бұрын

Пікірлер: 68
@calmyourmind5617
@calmyourmind5617 2 жыл бұрын
Very intelligent explaination... Not my cup of tea to understand. anyway thanks.
@NareshGupta
@NareshGupta 2 жыл бұрын
hehe - learn practice and apply is the key to success.
@InsaneRG4172
@InsaneRG4172 2 жыл бұрын
whats the space complexity and time complexity?
@imanhn
@imanhn 2 жыл бұрын
Nice 🙏
@midasama3124
@midasama3124 2 жыл бұрын
Time complexity is O(N) indeed. While loop while traversing string is 26*N is the worst case scenario.
@protyaybanerjee5051
@protyaybanerjee5051 3 жыл бұрын
Nice explanation
@NareshGupta
@NareshGupta 3 жыл бұрын
Keep watching
@deepankerchaudhary7187
@deepankerchaudhary7187 2 жыл бұрын
You earned a subscriber good explanation
@NareshGupta
@NareshGupta 2 жыл бұрын
Thanks and welcome
@muskangupta2545
@muskangupta2545 2 жыл бұрын
Thanks for this wonderful explanation
@NareshGupta
@NareshGupta 2 жыл бұрын
Thanks
@monkeytrollhunter
@monkeytrollhunter 4 жыл бұрын
I spent an hour and I couldn't get it. so I am here. Thank you
@NareshGupta
@NareshGupta 4 жыл бұрын
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-eg7ke
@ManishKumar-eg7ke 3 жыл бұрын
nice one
@NareshGupta
@NareshGupta 3 жыл бұрын
Thanks
@heisenberg1844
@heisenberg1844 3 жыл бұрын
Can you please tell how did you conclude you need a while loop and not a simple if check (just remove the top)?
@neerajkorde
@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.
@duongphan219
@duongphan219 2 жыл бұрын
So easy to understand. Thanks
@NareshGupta
@NareshGupta 2 жыл бұрын
Thanks
@davidjunghan91
@davidjunghan91 4 жыл бұрын
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..
@NareshGupta
@NareshGupta 4 жыл бұрын
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.
@davidjunghan91
@davidjunghan91 4 жыл бұрын
Thank you for replying. I’ll try the standard problems in high priority
@NareshGupta
@NareshGupta 4 жыл бұрын
Either follow leetcode explore or interviewbit ds-algo section.
@rajatgarg2166
@rajatgarg2166 4 жыл бұрын
I'm able to understand your approach. Thanks
@NareshGupta
@NareshGupta 4 жыл бұрын
You are welcome!
@nayankhuman1043
@nayankhuman1043 4 жыл бұрын
very good explanation sir !!!
@NareshGupta
@NareshGupta 4 жыл бұрын
Thanks and welcome
@VishalSharma-hq5ti
@VishalSharma-hq5ti 3 жыл бұрын
We could do it without stack also rt?
@satishshingade8514
@satishshingade8514 3 жыл бұрын
thanks for the solution the problem was really tricky and it was almost looking like dp ..
@willturner3440
@willturner3440 3 жыл бұрын
Dp? Where you find here dp
@siddharthb2226
@siddharthb2226 3 жыл бұрын
@@willturner3440 lavday, he said it looks like dp. Didnt say it was dp
@hodex5763
@hodex5763 3 жыл бұрын
What do we mean by lexicographical order
@NareshGupta
@NareshGupta 3 жыл бұрын
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".
@hodex5763
@hodex5763 3 жыл бұрын
@@NareshGupta then why not abcd but acbd I searched on Google didn't understood that's why came here
@NareshGupta
@NareshGupta 3 жыл бұрын
@@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.
@justshanky3012
@justshanky3012 3 жыл бұрын
How is the time complexity O(n) when we are using a stack? That while loop might also take some time right?
@ayushagrawal6473
@ayushagrawal6473 3 жыл бұрын
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).
@praveenj3112
@praveenj3112 4 жыл бұрын
We can add unique character in the stack and sort it . Is this work ?
@NareshGupta
@NareshGupta 4 жыл бұрын
No, check second example if you sort unique chars abcd will be answer which is not expected.
@praveenj3112
@praveenj3112 4 жыл бұрын
@@NareshGupta yes I got it . Thanks
@PritamKumar-mr5dv
@PritamKumar-mr5dv 3 жыл бұрын
cool
@paragroy5359
@paragroy5359 3 жыл бұрын
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
@NareshGupta
@NareshGupta 3 жыл бұрын
Thanks. Yes, correct that is the reason keep doing practice.
@dipteshsil9299
@dipteshsil9299 4 жыл бұрын
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.
@NareshGupta
@NareshGupta 4 жыл бұрын
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.
@willturner3440
@willturner3440 3 жыл бұрын
Please make playlist on placement preparation
@NareshGupta
@NareshGupta 3 жыл бұрын
Can you help me to share collection of problems
@willturner3440
@willturner3440 3 жыл бұрын
@@NareshGupta yes, share your mail. Then I'll..
@adarshsharmanit356
@adarshsharmanit356 3 жыл бұрын
Appreciated Brother !! THanks , Liked ur solution !!
@NareshGupta
@NareshGupta 3 жыл бұрын
Always welcome
@davidjunghan91
@davidjunghan91 4 жыл бұрын
This time it's not easy to understand. But I'll try more
@NareshGupta
@NareshGupta 4 жыл бұрын
Keep trying unless you clearly understand
@tieqi5623
@tieqi5623 4 жыл бұрын
Watch your video everyday, Really appreciate it. One little suggestion is do better hand writing when you draw the diagram :)
@NareshGupta
@NareshGupta 4 жыл бұрын
Noted
@vedantagarwal22
@vedantagarwal22 4 жыл бұрын
You do very good work sir, thankyou !
@NareshGupta
@NareshGupta 4 жыл бұрын
Thanks and You are welcome
@elliotho3015
@elliotho3015 2 жыл бұрын
really helpful, thank you!
@Ice-2706
@Ice-2706 4 жыл бұрын
it was a nice and easy explanation... good job !!
@NareshGupta
@NareshGupta 4 жыл бұрын
Thanks, Glad it helped!
@neerajkorde
@neerajkorde Жыл бұрын
bhai teri handwriting doctor se bhi advanced hai
@bhargavsai2449
@bhargavsai2449 3 жыл бұрын
tu
@deepakjaiswal1722
@deepakjaiswal1722 4 жыл бұрын
Giving runtime error
@NareshGupta
@NareshGupta 4 жыл бұрын
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
@rhythmjayee9707
@rhythmjayee9707 4 жыл бұрын
very good explanation. Thanks a lot!! keep the good work.
@NareshGupta
@NareshGupta 4 жыл бұрын
Thanks. You are welcome!
@priyanshu.tiwari
@priyanshu.tiwari 4 жыл бұрын
Very poorly explained. Please don't make videos like these.
@NareshGupta
@NareshGupta 4 жыл бұрын
What part you didn't understood and not clear?
Remove Duplicate Letters | Leetcode 316 | Stack | Day-18
21:00
Ayushi Sharma
Рет қаралды 12 М.
REMOVE DUPLICATE LETTERS | LEETCODE 316 | PYTHON STACK SOLUTION
18:15
Cracking FAANG
Рет қаралды 2,3 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 6 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 68 МЛН
Каха и лужа  #непосредственнокаха
00:15
Человек паук уже не тот
00:32
Miracle
Рет қаралды 4,2 МЛН
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 672 М.
Remove Duplicate Letters | Leetcode #316
14:55
Techdose
Рет қаралды 27 М.
316. Remove Duplicate Letters | Day 015 | Stack
13:36
Aryan Mittal
Рет қаралды 2,2 М.
316. Remove Duplicate Letters - Monotonic Stack - JavaScript
15:28
LeetCodeWithMonu
Рет қаралды 464
Why You NEED To Learn FastAPI | Hands On Project
21:15
Travis Media
Рет қаралды 167 М.
Remove Duplicate Letters | Leetcode 316
14:42
Tech Adora by Nivedita
Рет қаралды 1,9 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 6 МЛН