Amazon OA SDE 2 discussion
- Posted
- 7 Aug 2026
Summary
I was asked the "Maximum Coins From K Consecutive Bags" problem during an online assessment.
How it went
Got asked this question but with a different language. 3413. Maximum Coins From K Consecutive Bags
Questions asked (1)
- 01
Maximum Coins From K Consecutive Bags
Data Structures & Algorithms · Medium
Open the problemYou are given an array
bagsof lengthnwherebags[i]represents the number of coins in thei‑th bag. You can select exactlykconsecutive bags in one operation and collect all coins from those bags. After each operation, the selected bags become empty (their values become 0). You repeat the operation until all bags are empty. Return the maximum total number of coins you can collect.Example
Input: bags = [1,2,3,4,5], k = 2 Output: 12 Explanation: - First select bags[3] and bags[4] (values 4 and 5) -> collect 9, bags become [1,2,3,0,0] - Then select bags[1] and bags[2] (values 2 and 3) -> collect 5, bags become [1,0,0,0,0] - Finally select bags[0] and bags[1] (value 1 and 0) -> collect 1, total = 9+5+1 = 15.Note: The above example is illustrative; actual optimal selections may differ.