Maximum Chocolates from Jars (L.C. 198 :)
Updated
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
More Cisco interview questions
- Check if a String Is a PalindromePHONE SCREEN · Seen Nov 2026
- Find Unique ElementsPHONE SCREEN · Seen Nov 2026
- First Letter to Appear TwicePHONE SCREEN · Seen Nov 2026
- Middle of a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a Linked ListPHONE SCREEN · Seen Nov 2026
- Reverse a StringPHONE SCREEN · Seen Nov 2026
- Valid ParenthesesPHONE SCREEN · Seen Nov 2026
- K-Step Bit Flip with RetentionPHONE SCREEN · Seen Nov 2026
- Todo Task Manager OperationsONSITE INTERVIEW · Seen Oct 2026
- Find the Duplicate Number Without Modifying the ArrayONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Speed Up a Slow FunctionCitadel · OA · PHONE SCREENCitadel interview questions
- Maximum Income from Asset TradingJefferies · OA
- Best Time to Buy and Sell StockFlexTrade · OAFlexTrade interview questions
- Count Sawtooth SubarraysHudson River Trading · OAHudson River Trading interview questions
- Maximum Total of Nonadjacent RatingsMorgan Stanley · OAMorgan Stanley interview questions
- Count Sawtooth SubarraysTikTok · OATikTok interview questions
- Count Alternating-Parity SubarraysVisa · OAVisa interview questions
- Maximum Sum of Non-Adjacent ElementsLSEG · OALSEG interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Maximum Beauty by DeletionsMeesho · OA