FastPrepMaximum Chocolates from Jars (L.C. 198 :)
Problems/Maximum Chocolates from Jars (L.C. 198 :)

Maximum Chocolates from Jars (L.C. 198 :)

Cisco logoCisco● EasyNEW GRADOA
QuestionFunctionExamplesConstraints

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[]) → int

Examples

Example 1

jars = [5, 30, 99, 60, 5, 10]return = 114

Andrew 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, where N = jars.length
  • 0 ≤ jars[i] ≤ 10^4

More Cisco problems

  • Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
  • Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
  • Find Unique ElementsPHONE SCREEN · Seen Nov 2026
All Cisco interview questionsSee Cisco hiring insights
Saved
class Solution {
    public int maximumChocolates(int[] jars) {
      // write your code here
    }

}
Checking account…