Leetcode 3413. Maximum Coins From K Consecutive Bags
Given non-overlapping segments where every integer position in [li, ri] holds ci coins, find the maximum total coins covered by any contiguous window of k integer positions. Coordinates and k are up to 1e9, so the challenge is to slide/sweep a length-k window efficiently over sparse weighted intervals without expanding individual positions.
Asked at:
Amazon
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early July, 2026
Amazon
Mid-level
There are an infinite amount of bags on a number line, one bag for each coordinate. Some of these bags contain coins. You are given a 2D array coins, where coins[i] = [li, ri, ci] denotes that every bag from li to ri contains ci coins. The segments that coins contain are non-overlapping. You are also given an integer k. Return the maximum amount of coins you can obtain by collecting k consecutive bags. Example 1: Input: coins = [[8,10,1],[1,3,2],[5,6,4]], k = 4 Output: 10 Explanation: Selecting bags at positions [3, 4, 5, 6] gives the maximum number of coins: 2 + 0 + 4 + 4 = 10. Example 2: Input: coins = [[1,10,3]], k = 2 Output: 6 Explanation: Selecting bags at positions [1, 2] gives the maximum number of coins: 3 + 3 = 6.
Hello Interview Premium
Your account is free and you can post anonymously if you choose.