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.
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
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]
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!
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.
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)?
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
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.
@@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.
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.
appreciate it, its the same for me :)
And this is how your boss think of giving salary to you
Oh I was waiting for you :) yes the problem is poorly worded I feel
I only thought about iterating through left -> right..always amazing
same 🤧
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
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]
Thanks man you're so good that I never had to wait for you to code.
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!
Same dude
same
very well explained!
just like interview style!
Amazing explanation !!!!. Greedy Questions are just mind blowing.
Yea, greedy hits you up as if you never know what has happened.
Thanks for uploading this. I had requested for this in the comments in one of your videos.
You are totally more than awesome
You explained this concept in such an awesome manner I have no words for it
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.
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)?
Yep, that's my bad. Space is O(n)
@@NeetCodeIO Thanks for clarifying! appreciate your efforts and explanations 👍🏼
Quite much easier problem than lots of "easy" ones.
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
Thank You So Much for this wonderful video...🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
literally the best explaination
Wait is over guys 😅
how you get so good at logic, damn nice and nice , best approach
isn't it O(n) space solution as we are using extra array to store candies ?
Best Explanation 👏🏻 Nice work great intution
I have seen a 0(1) space solution in lc solution section. Could u explain it in a future vid
was waiting for this
11:52 precisely. Did you make that same mistake there?
Finally solved the problem. Thank you so much!
solve on your own,give your everything to solve the problem
@@RishabhSingh-xn3xu 🤣
Genius explanation... Wow
Best explanation ever
First LC hard I solved on my own! :)
Cool buddy
good job man. very helpful series......
Was waiting for this :)
You're a genius
I missed that "welocme back" this morning...
Great explaination ❤
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.
@@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.
@@aisteelmemesforaliving I'm also looking for a better explanation of that algorithm. If I figure it out, I'll make a video.
@@stefanopalmieri9201 please don't forget to reply to this if you actually do. Highly appreciated.
@@aisteelmemesforaliving It's uploaded now: ua-cam.com/video/_l9N_LcplLs/v-deo.html
any luck?@@aisteelmemesforaliving
the problem is not enough described in leetcode
12:08 stuck 2 days because i did not take that into account
How to get referrals brother, I worked really hard , solved 500+ problems on leetcode but still I m suffering to get interviews
Please help me I m sm out of hope right now
I feel you man, me too.
Well explained 👍
this one looks easy after seeing solution ,but how to endup with this intuition !!!
Thanks for the daily
Can you explain one pass approach?
This was asked to me in an interview and of course, I messed it up😭
very clever
It's O(n) additional memory, isn't it?
This is an O(N) space solution but a O(1) space solution does exist for this problem.
The best
How i can get big brain like your?
I have no idea how I could figure this out on my own tbh
Now do it using O(1) space
Corporate in a nutshell
im too dumb for this shit chief
not pertaining to the question or this video, but what's the difference between this channel and the original channel? @neetcode