Candies
Solutions This problem can be solved with a greedy approach.
First of all, we distribute one candy to every child.
Then we can iterate adjacent children from left to right: if one is higher than the other but has less chandies, we give her a candy more.
Similarly, we do the same from right to left.
Here is a C++ implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 int N; cin >> N; vector<int> v, candies; v.
[Read More]