Remove K digits | Build lowest number | Leetcode

  Рет қаралды 87,983

Techdose

Techdose

4 жыл бұрын

This video explains a very important programming interview question which is ti find the smallest number after removing K digits from a given number. This is a very interesting and also a very important question. At first glace, it might seem easy but it has many special cases. I have first explained the possible cases and then the intuition for solving this problem. This can be solved very easily using a stack. At the end of the video, i have explained the
CODE and shown some more special cases and how to handle them. CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
CODE LINK: gist.github.com/SuryaPratapK/...

Пікірлер: 276
@nishanksoni7120
@nishanksoni7120 4 жыл бұрын
You are doing too much hard work dude.Wish you best of luck for your future endeavours.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@gracioussaxena8318
@gracioussaxena8318 4 жыл бұрын
Did you just fire the guy lol Great job though Tech Dose, well explained!
@nirajgusain1452
@nirajgusain1452 2 жыл бұрын
Hey there, I am from year 2022, I came back in time to give you good news that ,Surya sir(tech dose founder) has joined Google.🥳
@codingwave56
@codingwave56 3 ай бұрын
@@nirajgusain1452 wow ! 🎉
@fullysimplified7139
@fullysimplified7139 2 жыл бұрын
Can't be explained better than this... Million times thanks for making these questions so simple :)
@bharathik6479
@bharathik6479 4 жыл бұрын
Wonderful way of explaining the algorithm behind the program. Most channels only explain(show) the code. Please keep up this great work. Please do mostly asked Leetcode medium questions. Will be a great help. Thanks a lot.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@dallasgannon5717
@dallasgannon5717 2 жыл бұрын
Sorry to be off topic but does any of you know of a way to log back into an Instagram account..? I stupidly forgot the account password. I would appreciate any tips you can give me!
@johnnyzyaire602
@johnnyzyaire602 2 жыл бұрын
@Dallas Gannon instablaster :)
@dallasgannon5717
@dallasgannon5717 2 жыл бұрын
@Johnny Zyaire I really appreciate your reply. I found the site thru google and im in the hacking process now. Takes quite some time so I will reply here later when my account password hopefully is recovered.
@dallasgannon5717
@dallasgannon5717 2 жыл бұрын
@Johnny Zyaire it did the trick and I now got access to my account again. Im so happy! Thanks so much you saved my account :D
@sudhanshuverma1987
@sudhanshuverma1987 2 жыл бұрын
Awesome explanation. You’re doing a great job in helping the community.
@0anant0
@0anant0 3 жыл бұрын
Awesome explanation! Thanks! As per the explanation, just remember this: Remove previously seen peak elem to flatten the curve. When graph dips, we have already seen a peak.
@dayanandraut5660
@dayanandraut5660 3 жыл бұрын
One of the best intuitions I have ever seen. I love the way you take examples to derive the logic. Keep it up. And also thanks for delivering such a quality content on coding problems. You just earned a subscriber.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@ujjvalsharma5055
@ujjvalsharma5055 4 жыл бұрын
wonderful video. Great explanation of code and intuition. Keep up the good work
@yitingg7942
@yitingg7942 3 жыл бұрын
This is absolutely mind blowing. Couldn't think of this approach.. 😭😭😭 Also so many edges cases to handle... But great great video.
@blynch2496
@blynch2496 4 жыл бұрын
Perfect, clear explanation to a problem that I've been stuck on. Thanks so much!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@AmanShukla18031992
@AmanShukla18031992 4 жыл бұрын
The explanation was really awesome bro. Gave a whole new perspective to look at numbers. Really appreciate the effort. Sincerely, thank you.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@ytg6663
@ytg6663 2 жыл бұрын
Explain
@sameera2426
@sameera2426 3 ай бұрын
It was such a great explanation. Half way through the video and I knew what to do. Keep up the good work.
@amritanshu83
@amritanshu83 4 жыл бұрын
Very nice explanation better than other explanations out there which just throw terms like greedy etc. Giving concrete examples and explaining the algo through them makes it much easier to understand.
@techdose4u
@techdose4u 4 жыл бұрын
Yes....term confuses students 😅
@satyakidas7297
@satyakidas7297 2 жыл бұрын
Amazing intuition explained. Thank you
@paragroy5359
@paragroy5359 7 ай бұрын
Nice content. Keep on making such videos
@shivangshukla4243
@shivangshukla4243 4 жыл бұрын
God level explanation bro. Been watching your videos since a month and they are all brilliant. Will definitely donate once I land a job :)
@techdose4u
@techdose4u 4 жыл бұрын
Thanks for your appreciation.
@aamirjamal6833
@aamirjamal6833 3 жыл бұрын
I wish I could like this video more than once. Thanks for your explanation. You are good!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks 😊
@harishvemula6709
@harishvemula6709 4 жыл бұрын
Sir , the way you explain is absolutely amazing !! . Wish i had a teacher like you . Greatwork Sir !! :) :)
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@akashsingha2616
@akashsingha2616 4 жыл бұрын
Great explanation brother. Understood each and every step. Keep doing great work.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@ShubhamSharma1210
@ShubhamSharma1210 4 жыл бұрын
nice .. this is a good explanation. the good part is you are telling more examples that make more sense for everyone.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@anshimagarg9661
@anshimagarg9661 4 жыл бұрын
I'm so happy that I found your video. I understood it very well. Thank you very much sir.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@Darshil1771
@Darshil1771 3 жыл бұрын
Became fan of your explanation! Much much appreciated!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@SaiKiran-dy6ke
@SaiKiran-dy6ke 4 жыл бұрын
Man, wonderful explanation.. Highly appreciated.. 💞💞
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@akhilesh59
@akhilesh59 2 жыл бұрын
Nice Explanation! Thank you 😄
@asliddinburiev5143
@asliddinburiev5143 Жыл бұрын
Simple and perfect explanation!
@shrijonbiswas8105
@shrijonbiswas8105 Жыл бұрын
This is a phenomenal explanation!!
@culeforever5408
@culeforever5408 7 ай бұрын
great explaination
@kkgirl543
@kkgirl543 4 жыл бұрын
This is an amazing explanation! Nice question, thanks.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@niteenautade
@niteenautade 2 жыл бұрын
Beautifully explained.
@santoshreddy3
@santoshreddy3 3 жыл бұрын
Your explanations are best I have found on KZfaq.
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@himangshushekharjha6972
@himangshushekharjha6972 4 жыл бұрын
Simply Awesome! Keep Growing!!
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@piyushdanej3930
@piyushdanej3930 3 жыл бұрын
Pretty good explaination bro ! I was able to solve it in my mind but couldn't put it in code . DIdn't think about first-come maxima approach . Cheers (y)
@techdose4u
@techdose4u 3 жыл бұрын
Nice
@samridhshubham8109
@samridhshubham8109 10 ай бұрын
Wat an explanation, absolute gem
@AyushRaj-gf2ce
@AyushRaj-gf2ce 3 жыл бұрын
extremly datailed explanation..thank you so much!!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@vm1662
@vm1662 4 жыл бұрын
Amazing stuff! Thank you.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@collegeworld7494
@collegeworld7494 Жыл бұрын
Best concise explanation
@azadsingh8466
@azadsingh8466 2 жыл бұрын
Dude, congrats on 100K. You deserve it
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😄
@Shubham-zu1zh
@Shubham-zu1zh Жыл бұрын
good explaination
@adarshsasidharan254
@adarshsasidharan254 Жыл бұрын
man what a brilliant explanation
@aakashbhatia
@aakashbhatia 2 жыл бұрын
good explanation
@sundeeppenkay2162
@sundeeppenkay2162 4 жыл бұрын
Your explanation is really good and with O(N) which is better. I solved this problem with different approach and I think the time complexity id O(N * k). Is that correct? Step 1: Parse the string left to right. Step 2: For each current char at i, See if there is a char lesser than the current char in window [i+1 to i+k]. If found, decrement the k and skip the char. Otherwise add to the result. Here is the code: public String removeKdigits(String num, int k) { if(num == null || num.length() == 0 || num.length() 0){ builder.delete(builder.length()-rem, builder.length()); } String res = builder.toString(); return res.length() == 0? "0" : res; } int getMinIndex(char val, int start, int end, String num){ if(end >= num.length()){ return -1; } for(int i = start; i
@yadneshkhode3091
@yadneshkhode3091 2 жыл бұрын
your time complexity is N^2 and space complexity is also N
@hitenarya4987
@hitenarya4987 4 жыл бұрын
this channel should have millions of subs.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks bro :)
@greatbrothers2947
@greatbrothers2947 3 жыл бұрын
This channel work so hard i wish this channel should have millions of subscribers
@sleepypanda7172
@sleepypanda7172 2 жыл бұрын
pure genius!
@red_and_black_UA
@red_and_black_UA 2 жыл бұрын
great job, thanks for good quality of explanation
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😊
@lanpingdeng1094
@lanpingdeng1094 4 жыл бұрын
great explanation, easy to follow and understand. thanks
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@anuplohar23
@anuplohar23 3 ай бұрын
Nice Explanation
@luanaamorim5055
@luanaamorim5055 3 жыл бұрын
thanks so much, great explanation!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@sarthakkhetarpal8416
@sarthakkhetarpal8416 3 ай бұрын
great explanation
@suryanshgupta7518
@suryanshgupta7518 2 жыл бұрын
wonderfull way of explaining..
@techdose4u
@techdose4u 2 жыл бұрын
Thanks :)
@kongzilla2897
@kongzilla2897 3 жыл бұрын
Nice and clean :)
@abhishek__anand__
@abhishek__anand__ Жыл бұрын
Great Video
@anil7931
@anil7931 3 жыл бұрын
Thanks for clear explanation !!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@xapeuuu
@xapeuuu 4 жыл бұрын
Glad i got the stack approach by myself even though my code was way messier than yours ^^
@techdose4u
@techdose4u 4 жыл бұрын
Many were not able to solve this. Glad that you did :)
@PhenomenalInitiations
@PhenomenalInitiations 3 жыл бұрын
Can you please explain why in line 15 he consiered only when stack is not empty?
@oladimejijames9554
@oladimejijames9554 4 жыл бұрын
nice work sir, please keep it up. Kudos
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@thelimit9719
@thelimit9719 3 жыл бұрын
Perfect implementation !!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@jashhinger442
@jashhinger442 Жыл бұрын
Great explanation sir, Thanku so much
@techdose4u
@techdose4u Жыл бұрын
Welocome :)
@bhavyapandey
@bhavyapandey 3 жыл бұрын
An inspiration for anyone who wishes to learn or teach DSA
@techdose4u
@techdose4u 3 жыл бұрын
👍🏼
@spetsnaz_2
@spetsnaz_2 4 жыл бұрын
starting the day with your video
@techdose4u
@techdose4u 4 жыл бұрын
;D
@RahulKumar-oj4lz
@RahulKumar-oj4lz 2 жыл бұрын
Great Explanation
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@kaichenghu3826
@kaichenghu3826 4 жыл бұрын
Very good explanation and visualization
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@rajnisharyan6361
@rajnisharyan6361 4 жыл бұрын
hey, can you please tell me about how you are wrinting are you using digital pen and which software you are using for writing
@shaamidrees6036
@shaamidrees6036 2 жыл бұрын
Thanks
@istiyakahmed4117
@istiyakahmed4117 4 жыл бұрын
nice explanation! keep it up :D
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@crankyinmv
@crankyinmv 4 жыл бұрын
Thanks. I hate your 4's but the overall the video was quite helpful. I solved 402 with a different approach, but wanted to see how the stack based approach worked. No I know.
@techdose4u
@techdose4u 4 жыл бұрын
😅
@hapysethi1306
@hapysethi1306 4 жыл бұрын
Bhai thanks alot for sharing Algo Code and Explanation
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@sanketsuryawanshi
@sanketsuryawanshi 3 жыл бұрын
Very Well Explained sir 🔥👍🏻
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@codesnippets03
@codesnippets03 4 жыл бұрын
Amazing 👌 explaination
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@sachinduhan3022
@sachinduhan3022 4 жыл бұрын
amazing explanations man...
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@ShubhamSingh-fl3qi
@ShubhamSingh-fl3qi 4 жыл бұрын
This helps alot ThankYou sir
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@agileprogramming7463
@agileprogramming7463 4 жыл бұрын
Initially I thought this is a DP problem because I thought we have to consider all possible cases and the do the DP thing... but this approach is really wonderful.
@techdose4u
@techdose4u 4 жыл бұрын
It could have been dp problem if you thought about recursively solving this.
@vishalbhatane1608
@vishalbhatane1608 3 жыл бұрын
Thank you very much!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@karansagar7870
@karansagar7870 4 жыл бұрын
Great approach
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@dhruvvarshney1040
@dhruvvarshney1040 3 жыл бұрын
kya baap tarike se sikhaya bhai. Mja aagya. Thanks man
@techdose4u
@techdose4u 3 жыл бұрын
❤️
@nikhillingam4630
@nikhillingam4630 4 жыл бұрын
Best explanations ever
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@tirthjayswal9895
@tirthjayswal9895 4 жыл бұрын
Good
@AMITSHARMA-oh1nq
@AMITSHARMA-oh1nq 4 жыл бұрын
Can we use butmasking to reduce complexity to o(n)
@rahulchaubey8988
@rahulchaubey8988 4 жыл бұрын
Nicely explained..
@techdose4u
@techdose4u 4 жыл бұрын
Thanks:)
@sukeshreddy2286
@sukeshreddy2286 2 жыл бұрын
You are on fire!!!!
@shishirkakhandki9230
@shishirkakhandki9230 3 жыл бұрын
Thank you so much!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome
@abhishektanwar7902
@abhishektanwar7902 4 жыл бұрын
Amazing👌
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@Arunkumar-pg8kx
@Arunkumar-pg8kx 3 жыл бұрын
That was amazing,
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@ritikthakur2445
@ritikthakur2445 4 жыл бұрын
nice explanation ❤❤
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@kushgupta1187
@kushgupta1187 4 жыл бұрын
Very well explained
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@AnkitKumarCoder
@AnkitKumarCoder 4 жыл бұрын
Thank You!!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@srini580
@srini580 3 жыл бұрын
Thank You Sir!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@rajeshbammidy180
@rajeshbammidy180 4 жыл бұрын
One thing to notice here if the elements keeps on increasing as he said it will form the smallest number possible that means we will have the higer value digits at the end so we can remove them easily with the help of the stack
@techdose4u
@techdose4u 4 жыл бұрын
Yes correct :)
@ninehoursful
@ninehoursful 3 жыл бұрын
How does one come up with such intuitive solutions? I tried to come up with multiple solutions but was not even close to this solution. I tried to solve this question using priorityQueue, HashMaps, expanding from center of the string.
@anonymoussloth6687
@anonymoussloth6687 3 жыл бұрын
If the problem statement is reversed and we have to find the maximum number after deleting k digits, would we do the opposite by looking for where it rises instead of dips from left to right?
@shivam7929
@shivam7929 2 жыл бұрын
🔥🔥
@aswadk
@aswadk 4 жыл бұрын
Too Good!
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@user-zs7mu4oq8e
@user-zs7mu4oq8e 3 ай бұрын
thank uu
@harifrahman8054
@harifrahman8054 4 жыл бұрын
what is the time and space complexity for this solution definitely it wont be O(n*k) ?
@rohits22013
@rohits22013 4 жыл бұрын
good explanation man
@techdose4u
@techdose4u 4 жыл бұрын
Thanks man :)
@sparrowsurya96
@sparrowsurya96 2 жыл бұрын
I got a goodone idea to solve this say we have the number 71382 and k=2 so what we can do is that to divide the digit by its index number, index number must be starting from 0 ie for 7 index number should be 1 not 0 and so on,, then after we got the list of the divided result we can just chose the minimums possible and then we can include only those in return value, me testing this got all correct result for almost all cases
@jolly_dollyyy
@jolly_dollyyy 2 жыл бұрын
Lucid Explanation!!
@techdose4u
@techdose4u 2 жыл бұрын
Thanks 😊
@karthikchandra7303
@karthikchandra7303 Жыл бұрын
Hi sir amazing explanation the method looked very nice, but i dont think it will work for numbers with trailing zeros in the end
@vishnuparegi4580
@vishnuparegi4580 4 жыл бұрын
👌
@techdose4u
@techdose4u 4 жыл бұрын
👍
@vinayak186f3
@vinayak186f3 3 жыл бұрын
Can this be solved using some variation of knapsack , considering size =n-k , values 1 4 3 7 2 9 , as each digit may come or may not come in the solution .
@saianushachodapaneedi7504
@saianushachodapaneedi7504 4 жыл бұрын
Thank you....
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@ojobabatunde8415
@ojobabatunde8415 4 жыл бұрын
Thanks man
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@shwetanksingh5438
@shwetanksingh5438 4 жыл бұрын
Thanks man :)
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
Online Stock Span | Previous greater element | Leetcode #901
13:33
Remove K Digits | Intuition | Dry Run | Leetcode 402 | codestorywithMIK
35:07
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 16 МЛН
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 62 МЛН
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 16 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 474 М.
Java Is Better Than Rust
42:14
ThePrimeTime
Рет қаралды 163 М.
Remove K Digits - Leetcode 402 - Python
14:36
NeetCode
Рет қаралды 59 М.
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
OpenAI's New SearchGPT Shakes Up the Industry, Google Stock CRASHES!
10:10
Trapping Rainwater Problem | Leetcode #42
34:12
Techdose
Рет қаралды 96 М.
Jump game | Leetcode #55 | Valley peak approach
12:28
Techdose
Рет қаралды 184 М.
I solved 541 Leetcode problems. But you need only 150.
7:42
Sahil & Sarra
Рет қаралды 2,3 МЛН
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 146 М.
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 16 МЛН