Candy - Leetcode 135 - Python

  Рет қаралды 33,791

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 70
@LeeK301
@LeeK301 7 ай бұрын
One way I try to challenge myself when solving these problems: If I can't solve intitally and I am just stuck, come to NeetCode's videos and watch the intuition portion. If I feel like I have a good idea of what he's talking about, I will pause the video and attempt to solve again under a time limit. If I can't solve it again, I will come back to his vid and watch for the solution as well.
@RhoBustDev
@RhoBustDev Ай бұрын
appreciate it, its the same for me :)
@victortruong2538
@victortruong2538 Жыл бұрын
Oh I was waiting for you :) yes the problem is poorly worded I feel
@0brooo
@0brooo 6 ай бұрын
THIS is a valid solution to this problem. I was looking at the solutions with the most upvotes, and their solution was to mathematically solve it by adding up all the longest increasing subarray and decreasing subarray, and then subtracting the lowest of the two from the totalCandy. I hate that leetcode solutions have become mathematically solutions rather than programming. Solutions for the CarFleet problem is a hashmap with the key being the product of a formula. Then returning all the unique keys. Like what is that, the solution should go through a process that imitates the problem. Now we’re seeing problems that are purely solved by inventing a formula for the specific issue. Rather than preparing you for problems you’ll face regularly
@HtotheG
@HtotheG Жыл бұрын
I came up with the O(n^2) solution with a while loop of while(candyIncreasedThisLoop){ do a pass and add 1 if the rules arent followed for each } and I was proud of myself, but damn this code is not only neat is damn near beautiful 😢 Thank you for the great explanation as always you are a huge help in my career journey as a new grad at the moment. I can't thank you enough for your years of backlogs of coding solutions I am learning from right now. Keep up the amazing work!
@harshiv2005
@harshiv2005 9 ай бұрын
Same dude
@cody-wq7zc
@cody-wq7zc 9 ай бұрын
same
@adamlin2301
@adamlin2301 8 ай бұрын
And this is how your boss think of giving salary to you
@HR-pz7ts
@HR-pz7ts 8 ай бұрын
Thanks man you're so good that I never had to wait for you to code.
@VarunMittal-viralmutant
@VarunMittal-viralmutant 2 ай бұрын
An alternate to the last step: if ratings[i] > ratings[i+1]: arr[i] = max(arr[i], arr[i+1]+1) That was more intuitive for me: if ratings[i] > ratings[i+1] and arr[i]
@JasonAhn-u5u
@JasonAhn-u5u Жыл бұрын
I only thought about iterating through left -> right..always amazing
@studimeyt5219
@studimeyt5219 Жыл бұрын
same 🤧
@GuruPrasadShukla
@GuruPrasadShukla Жыл бұрын
very well explained! just like interview style!
@CognitiveAnkit
@CognitiveAnkit 10 ай бұрын
You are totally more than awesome You explained this concept in such an awesome manner I have no words for it
@dineshkumarkb1372
@dineshkumarkb1372 Жыл бұрын
Thanks for uploading this. I had requested for this in the comments in one of your videos.
@hannibalm090009
@hannibalm090009 Жыл бұрын
Thanks a lot bro, I actually just solved it had to pause the video at the mid of the intuition because that was the missing part that I needed, went and solved it then got back.
@abdelrahmanashraf1510
@abdelrahmanashraf1510 Жыл бұрын
You mentioned that no extra memory is needed, yet your solution clearly allocated a new array to track the number of candies given. Doesn't that make the space complexity O(n)?
@NeetCodeIO
@NeetCodeIO Жыл бұрын
Yep, that's my bad. Space is O(n)
@abdelrahmanashraf1510
@abdelrahmanashraf1510 Жыл бұрын
@@NeetCodeIO Thanks for clarifying! appreciate your efforts and explanations 👍🏼
@socialbeing5591
@socialbeing5591 7 ай бұрын
literally the best explaination
@iCodeStuff69
@iCodeStuff69 10 ай бұрын
Quite much easier problem than lots of "easy" ones.
@schrodingerskatt222
@schrodingerskatt222 Жыл бұрын
Amazing explanation !!!!. Greedy Questions are just mind blowing.
@AyushSharma-ux4fk
@AyushSharma-ux4fk Жыл бұрын
Yea, greedy hits you up as if you never know what has happened.
@joey_zhu
@joey_zhu 7 ай бұрын
I derived my solution by going deep into the diffs array and trying to reduce it to other problems, my soln ended up going to 30+ lines so i was quite disappointed to go into the solutions and see that ppl had done it in like 10 lines
@CodeWithRVR
@CodeWithRVR Жыл бұрын
Wait is over guys 😅
@CodeSuccessChronicle
@CodeSuccessChronicle 6 ай бұрын
Best Explanation 👏🏻 Nice work great intution
@jaishriharivishnu
@jaishriharivishnu 5 ай бұрын
how you get so good at logic, damn nice and nice , best approach
@stith_pragya
@stith_pragya Жыл бұрын
Thank You So Much for this wonderful video...🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@deepakjain248
@deepakjain248 9 ай бұрын
isn't it O(n) space solution as we are using extra array to store candies ?
@omdandade8245
@omdandade8245 Жыл бұрын
I missed that "welocme back" this morning...
@VidyaBhandary
@VidyaBhandary Жыл бұрын
Genius explanation... Wow
@krateskim4169
@krateskim4169 Жыл бұрын
was waiting for this
@elizabethr5161
@elizabethr5161 8 ай бұрын
Best explanation ever
@aisteelmemesforaliving
@aisteelmemesforaliving Жыл бұрын
Seems like this problem can be solved in one pass too, but I have a hard time understanding that lol. Would've been nice if you could explain the onepass method because I can understand your explanations only. Others take way too much time drawing, or do a poor job of explaining.
@aisteelmemesforaliving
@aisteelmemesforaliving Жыл бұрын
​@@Stay_away_from_my_swamp_waterno, apparently, you can use three variables up, down and peak and then do something which I don't understand to complete this in one pass and O(1) space complexity. It's the top solution on solutions page (by vanAmsen). I don't think I can post links here, the spam filter will probably go off.
@stefanopalmieri9201
@stefanopalmieri9201 Жыл бұрын
@@aisteelmemesforaliving I'm also looking for a better explanation of that algorithm. If I figure it out, I'll make a video.
@aisteelmemesforaliving
@aisteelmemesforaliving Жыл бұрын
@@stefanopalmieri9201 please don't forget to reply to this if you actually do. Highly appreciated.
@stefanopalmieri9201
@stefanopalmieri9201 Жыл бұрын
@@aisteelmemesforaliving It's uploaded now: kzbin.info/www/bejne/lZ2cf5KCmNWfgtU
@himanshu6489
@himanshu6489 9 ай бұрын
any luck?@@aisteelmemesforaliving
@FUNTasticFlutter
@FUNTasticFlutter 7 ай бұрын
good job man. very helpful series......
@aditya-lr2in
@aditya-lr2in Жыл бұрын
Was waiting for this :)
@ishaqniloy1532
@ishaqniloy1532 Жыл бұрын
Finally solved the problem. Thank you so much!
@RishabhSingh-xn3xu
@RishabhSingh-xn3xu 11 ай бұрын
solve on your own,give your everything to solve the problem
@pixelup4929
@pixelup4929 8 ай бұрын
@@RishabhSingh-xn3xu 🤣
@Meridian-lk2fo
@Meridian-lk2fo Жыл бұрын
First LC hard I solved on my own! :)
@simranvedpathak7112
@simranvedpathak7112 Жыл бұрын
Cool buddy
@truongtran99_
@truongtran99_ 7 ай бұрын
You're a genius
@aadityakiran_s
@aadityakiran_s 9 ай бұрын
11:52 precisely. Did you make that same mistake there?
@mahinhossen4251
@mahinhossen4251 10 ай бұрын
I have seen a 0(1) space solution in lc solution section. Could u explain it in a future vid
@becomingbesthackerprogramm4644
@becomingbesthackerprogramm4644 Жыл бұрын
How to get referrals brother, I worked really hard , solved 500+ problems on leetcode but still I m suffering to get interviews
@becomingbesthackerprogramm4644
@becomingbesthackerprogramm4644 Жыл бұрын
Please help me I m sm out of hope right now
@Jambajakumba
@Jambajakumba Жыл бұрын
I feel you man, me too.
@apoorvasingh5702
@apoorvasingh5702 7 ай бұрын
Well explained 👍
@Manishgupta200
@Manishgupta200 9 ай бұрын
Great explaination ❤
@uptwist2260
@uptwist2260 Жыл бұрын
Thanks for the daily
@chinni469
@chinni469 27 күн бұрын
This was asked to me in an interview and of course, I messed it up😭
@Antinormanisto
@Antinormanisto 8 ай бұрын
How i can get big brain like your?
@satwiktatikonda764
@satwiktatikonda764 Жыл бұрын
this one looks easy after seeing solution ,but how to endup with this intuition !!!
@suniln9029
@suniln9029 10 ай бұрын
Can you explain one pass approach?
@ahamedsha9688
@ahamedsha9688 11 ай бұрын
the problem is not enough described in leetcode 12:08 stuck 2 days because i did not take that into account
@stefanopalmieri9201
@stefanopalmieri9201 Жыл бұрын
This is an O(N) space solution but a O(1) space solution does exist for this problem.
@hwang1607
@hwang1607 4 ай бұрын
Now do it using O(1) space
@hwval-zw4hy
@hwval-zw4hy 10 ай бұрын
It's O(n) additional memory, isn't it?
@mohithadiyal6083
@mohithadiyal6083 Жыл бұрын
The best
@CS_n00b
@CS_n00b 8 ай бұрын
I have no idea how I could figure this out on my own tbh
@PriyaSharma-z5e3o
@PriyaSharma-z5e3o Ай бұрын
Corporate in a nutshell
@langacristian8366
@langacristian8366 7 ай бұрын
im too dumb for this shit chief
@pryshrng
@pryshrng Жыл бұрын
not pertaining to the question or this video, but what's the difference between this channel and the original channel? @neetcode
Gas Station - Greedy - Leetcode 134 - Python
15:47
NeetCode
Рет қаралды 142 М.
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 86 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 60 МЛН
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 303 М.
Game of Life - Leetcode 289 - Python
17:36
NeetCode
Рет қаралды 43 М.
Maximum Swaps - Leetcode 670 - Python
15:40
NeetCodeIO
Рет қаралды 13 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 674 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 586 М.
Text Justification - Leetcode 68 - Python
17:52
NeetCodeIO
Рет қаралды 29 М.
Leetcode 135 - Candy - O(N)/O(1) Solution Explained
5:05
Teaspoon AI
Рет қаралды 1 М.
Implement Trie (Prefix Tree) - Leetcode 208
18:56
NeetCode
Рет қаралды 213 М.
Number of Music Playlists - Leetcode 920 - Python
21:36
NeetCodeIO
Рет қаралды 13 М.
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 86 МЛН