15.Candy
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements:
Each child must have at least one candy.
Children with a higher rating get more candies than their neighbors.
Solution : (Using two arrays)
Approach: We maintain 2 arrays left neighbor and right neighbor. Left Arr: (Assuming Right neighbour gets more candy than left) Right Arr: (Assuming Left neighbour gets more candy than right) Find the max of both the left and right.
Last updated