You are viewing a single comment's thread. Return to all comments →
can thi algo traverse 9,8,7,7,6,6,5,4,3,
i think no????
Sure it does.
After the forward sweep, each child has 1 candy because each child has a rating equal to or less than that of its predecessor.
After the backward sweep, the 5th child has 1 candy and the 6th child has 4 candies (because the each have a rating of 6) while the 3rd child has 1 candy and the 4th child has 2 candies (because they each have a rating of 7).
So, the final rating:candies distribution is:
9:3 8:2 7:1 7:2 6:1 6:4 5:3 4:2 3:1 for a total of 19 candies.
thanks alot !!ur this post helped me!!
How about :
9:2 5:1 8:2 7:1 7:2 6:1 6:3 4:2 3:1 -> 15 candies
there may be a better solution
their positions are fixed