Maximum Chocolates from Jars (L.C. 198 :)
Problem statement
There are N jars of chocolates in a row. Jar i contains jars[i] chocolates, and some jars may be empty. Andrew can pick chocolates from any jars he likes, but he cannot pick from two jars that are next to each other. When he picks a jar, he takes all of its chocolates.
Return the maximum number of chocolates Andrew can pick.
Function
maximumChocolates(jars: int[]) → intExamples
Example 1
jars = [5, 30, 99, 60, 5, 10]return = 114Andrew picks from the 1st (5), 3rd (99) and 6th (10) jars. No two of them are next to each other, and 5 + 99 + 10 = 114. So, the output is 114.
Constraints
1 ≤ N ≤ 1000, whereN = jars.length0 ≤ jars[i] ≤ 10^4