Do neighboring children with equal rating get unequal candies


  • 3
    K

    Hi
    When the question said children with higher rating get more candies than their neighbors, I assumed
    that neighbor children with equal rating get equal candies

    Case 1 (I agree with this)
    Problem: [2, 2]
    Solution: 2 Explanation: children are given [1,1] candies

    Case 2 (Not clear)
    Problem: [1, 2, 2]
    Actual Solution: 5.

    The children must be given [1, 2, 2] candies. The first one must get atleast 1. Which means the second one must get atleast 2.
    So the third child is also given 1? So neighbor children with equal rating get unequal candies?

    Is this not the case?

    Thank you
    Mukund


  • 0
    X

    Case 2 [1,2,2] shall give 4 candies, as [1,2,1].
    It suffices (1) everyone gets a candy
    (2) the one who has higher rate has more candies than neighbors.

    Equal rate does not mean higher rate.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.