Click here to see the full article post
Inside of the for loop why not added by 1: candies += count(up) + count(down) + Math.max(up, down);
@ArthurTang Fixed. Thanks.
Why same rating got different candies? In Approach #2, "...34,34..." ratings got "...1,2..." candies, it's unreasonable! Hope to correct the problem.
Will an interviewer really expect someone to come up with the slope based solution during an interview?
The slope-based solution was my first idea after brute force, but implementing it correctly is a huge pain and I doubt I'd be able to do it correctly in an interview.
In the last figure, ratings at 13 and 14 are different but the candy counts are the same. So is 18 and 19. Candy at 19 and 20 should be one.
@vinod23 Should we assume that rating values are all positive?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.