Candy - Leetcode 135 - Python

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 70

  • @adamlin2301
    @adamlin2301 11 місяців тому +17

    And this is how your boss think of giving salary to you

  • @victortruong2538
    @victortruong2538 Рік тому +19

    Oh I was waiting for you :) yes the problem is poorly worded I feel

  • @HR-pz7ts
    @HR-pz7ts 10 місяців тому +1

    Thanks man you're so good that I never had to wait for you to code.

  • @0brooo
    @0brooo 9 місяців тому +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 Рік тому +6

    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!

  • @VarunMittal-viralmutant
    @VarunMittal-viralmutant 4 місяці тому +3

    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]

  • @GuruPrasadShukla
    @GuruPrasadShukla Рік тому +6

    very well explained!
    just like interview style!

  • @dineshkumarkb1372
    @dineshkumarkb1372 Рік тому

    Thanks for uploading this. I had requested for this in the comments in one of your videos.

  • @CognitiveAnkit
    @CognitiveAnkit Рік тому

    You are totally more than awesome
    You explained this concept in such an awesome manner I have no words for it

  • @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.

  • @schrodingerskatt222
    @schrodingerskatt222 Рік тому +2

    Amazing explanation !!!!. Greedy Questions are just mind blowing.

    • @AyushSharma-ux4fk
      @AyushSharma-ux4fk Рік тому +1

      Yea, greedy hits you up as if you never know what has happened.

  • @JasonAhn-u5u
    @JasonAhn-u5u Рік тому +6

    I only thought about iterating through left -> right..always amazing

  • @socialbeing5591
    @socialbeing5591 9 місяців тому

    literally the best explaination

  • @joey_zhu
    @joey_zhu 10 місяців тому

    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

  • @deepakjain248
    @deepakjain248 11 місяців тому +2

    isn't it O(n) space solution as we are using extra array to store candies ?

  • @abdelrahmanashraf1510
    @abdelrahmanashraf1510 Рік тому +5

    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  Рік тому +8

      Yep, that's my bad. Space is O(n)

    • @abdelrahmanashraf1510
      @abdelrahmanashraf1510 Рік тому

      @@NeetCodeIO Thanks for clarifying! appreciate your efforts and explanations 👍🏼

  • @CodeSuccessChronicle
    @CodeSuccessChronicle 9 місяців тому

    Best Explanation 👏🏻 Nice work great intution

  • @jaishriharivishnu
    @jaishriharivishnu 8 місяців тому

    how you get so good at logic, damn nice and nice , best approach

  • @stith_pragya
    @stith_pragya Рік тому +1

    Thank You So Much for this wonderful video...🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @iCodeStuff69
    @iCodeStuff69 Рік тому

    Quite much easier problem than lots of "easy" ones.

  • @elizabethr5161
    @elizabethr5161 10 місяців тому

    Best explanation ever

  • @Manishgupta200
    @Manishgupta200 11 місяців тому

    Great explaination ❤

  • @xiaotianwang7565
    @xiaotianwang7565 2 дні тому

    Hi, thanks for providing this brilliant solution. I understand that after left->right, every kid with higher ranking compared with their left neighbor will have more candies, and after right->left, every kid with higher ranking compared with their right neighbor will have more candies. However, how to make sure after second round from right to left, every kid with higher ranking compared with their left neighbor still have more candies?

  • @mahinhossen4251
    @mahinhossen4251 Рік тому +1

    I have seen a 0(1) space solution in lc solution section. Could u explain it in a future vid

  • @FUNTasticFlutter
    @FUNTasticFlutter 9 місяців тому

    good job man. very helpful series......

  • @truongtran99_
    @truongtran99_ 10 місяців тому

    You're a genius

  • @apoorvasingh5702
    @apoorvasingh5702 9 місяців тому

    Well explained 👍

  • @VidyaBhandary
    @VidyaBhandary Рік тому +1

    Genius explanation... Wow

  • @Meridian-lk2fo
    @Meridian-lk2fo Рік тому +1

    First LC hard I solved on my own! :)

  • @CodeWithRVR
    @CodeWithRVR Рік тому +2

    Wait is over guys 😅

  • @ishaqniloy1532
    @ishaqniloy1532 Рік тому

    Finally solved the problem. Thank you so much!

    • @RishabhSingh-xn3xu
      @RishabhSingh-xn3xu Рік тому

      solve on your own,give your everything to solve the problem

    • @pixelup4929
      @pixelup4929 10 місяців тому

      @@RishabhSingh-xn3xu 🤣

  • @aadityakiran_s
    @aadityakiran_s 11 місяців тому

    11:52 precisely. Did you make that same mistake there?

  • @aisteelmemesforaliving
    @aisteelmemesforaliving Рік тому +3

    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 Рік тому +1

      ​@@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: ua-cam.com/video/_l9N_LcplLs/v-deo.html

    • @himanshu6489
      @himanshu6489 11 місяців тому

      any luck?@@aisteelmemesforaliving

  • @ahamedsha9688
    @ahamedsha9688 Рік тому

    the problem is not enough described in leetcode
    12:08 stuck 2 days because i did not take that into account

  • @uptwist2260
    @uptwist2260 Рік тому

    Thanks for the daily

  • @suniln9029
    @suniln9029 Рік тому

    Can you explain one pass approach?

  • @krateskim4169
    @krateskim4169 Рік тому +1

    was waiting for this

  • @satwiktatikonda764
    @satwiktatikonda764 Рік тому

    this one looks easy after seeing solution ,but how to endup with this intuition !!!

  • @chinni469
    @chinni469 3 місяці тому

    This was asked to me in an interview and of course, I messed it up😭

  • @omdandade8245
    @omdandade8245 Рік тому

    I missed that "welocme back" this morning...

  • @piglovesasy
    @piglovesasy 2 місяці тому

    very clever

  • @aditya-lr2in
    @aditya-lr2in Рік тому

    Was waiting for this :)

  • @becomingbesthackerprogramm4644

    How to get referrals brother, I worked really hard , solved 500+ problems on leetcode but still I m suffering to get interviews

  • @Antinormanisto
    @Antinormanisto 11 місяців тому +1

    How i can get big brain like your?

  • @hwval-zw4hy
    @hwval-zw4hy Рік тому

    It's O(n) additional memory, isn't it?

  • @hwang1607
    @hwang1607 6 місяців тому

    Now do it using O(1) space

  • @stefanopalmieri9201
    @stefanopalmieri9201 Рік тому

    This is an O(N) space solution but a O(1) space solution does exist for this problem.

  • @mohithadiyal6083
    @mohithadiyal6083 Рік тому

    The best

  • @CS_n00b
    @CS_n00b 10 місяців тому

    I have no idea how I could figure this out on my own tbh

  • @PriyaSharma-z5e3o
    @PriyaSharma-z5e3o 3 місяці тому

    Corporate in a nutshell

  • @langacristian8366
    @langacristian8366 10 місяців тому

    im too dumb for this shit chief

  • @pryshrng
    @pryshrng Рік тому +1

    not pertaining to the question or this video, but what's the difference between this channel and the original channel? @neetcode