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! ༊·°🌺
jars = [5, 30, 99, 60, 5, 10] return = 114
1 ≤ N ≤ 1000- Collect CoinsSeen Jun 2025
- FizzBuzz ProblemSeen May 2025
- Find Largest Sum Contiguous SubarraySeen May 2025
- Find Largest Sum of Continuous SequenceSeen May 2025
- Find Palindrome Sub-stringSeen May 2025
- Flight Path Package DropSeen May 2025
- Count Numbers with Digit SumSeen Mar 2025
- Find Elements Largest in Row Smallest in ColumnSeen Mar 2025
public int maximumChocolates(int[] jars) {
// write your code here
}