Maximum Chocolates from Jars (L.C. 198 :)
Learn this problemProblem statement
There is a set of N jars containing chocolates. Some of them may be empty. Determine the maximum number of chocolates Andrew can pick from the jars given that he cannot pick from jars next to each other.
Write an algorithm to find the maximum number of chocolates that can be picked from the jars in such a way that the chocolates are not picked from jars next to each other.
Input
The first line of input consists of an integer- numJars, representing the number of jars (N).
The next line consists of N space-separated integers representing the number of chocolates in each jar.
Output
Print the maximum number of chocolates that can be picked from the jars in such a way that the chocolates are not picked from jars next to each other.
Constraints
1 ≤ N ≤ 1000
💐 spike carries! ༊·°🌺
Function
maximumChocolates(jars: int[]) → intExamples
Example 1
jars = [5, 30, 99, 60, 5, 10]return = 114Constraints
1 ≤ N ≤ 1000