Say if the rating is [1 2 3], we need at least 6 candies. But if we swap it to [1 3 2], only 4 candies are needed.
Good Idea! The question doesn't said not allow to swap children.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.