3413. Maximum Coins From K Consecutive Bags Medium
1/**
2 * [3413] Maximum Coins From K Consecutive Bags
3 *
4 * There are an infinite amount of bags on a number line, one bag for each coordinate. Some of these bags contain coins.
5 * You are given a 2D array coins, where coins[i] = [li, ri, ci] denotes that every bag from li to ri contains ci coins.
6 * The segments that coins contain are non-overlapping.
7 * You are also given an integer k.
8 * Return the maximum amount of coins you can obtain by collecting k consecutive bags.
9 *
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">coins = [[8,10,1],[1,3,2],[5,6,4]], k = 4</span>
13 * Output: <span class="example-io">10</span>
14 * Explanation:
15 * Selecting bags at positions [3, 4, 5, 6] gives the maximum number of coins: 2 + 0 + 4 + 4 = 10.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">coins = [[1,10,3]], k = 2</span>
20 * Output: <span class="example-io">6</span>
21 * Explanation:
22 * Selecting bags at positions [1, 2] gives the maximum number of coins: 3 + 3 = 6.
23 * </div>
24 *
25 * Constraints:
26 *
27 * 1 <= coins.length <= 10^5
28 * 1 <= k <= 10^9
29 * coins[i] == [li, ri, ci]
30 * 1 <= li <= ri <= 10^9
31 * 1 <= ci <= 1000
32 * The given segments are non-overlapping.
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/maximum-coins-from-k-consecutive-bags/
38// discuss: https://leetcode.com/problems/maximum-coins-from-k-consecutive-bags/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn maximum_coins(coins: Vec<Vec<i32>>, k: i32) -> i64 {
44
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_3413() {
56 }
57}
58
Back
© 2025 bowen.ge All Rights Reserved.