Imagine an infinite treasure hunt along a number line! There are bags at every integer coordinate, and some of these bags contain precious coins. You're given a 2D array coins where each element coins[i] = [l_i, r_i, c_i] tells you that every bag from position l_i to r_i (inclusive) contains exactly c_i coins.
Here's the catch: the coin segments don't overlap, so you have a clear map of where all the treasures are located. Your mission is to find the maximum number of coins you can collect by choosing any k consecutive bags along the number line.
Goal: Return the maximum coins you can obtain from k consecutive bags.
Input: A 2D array of coin segments and an integer k
Output: Maximum coins from k consecutive positions
Input & Output
Constraints
- 1 β€ k β€ 2 Γ 104
- 0 β€ coins.length β€ 103
- coins[i].length == 3
- 1 β€ li β€ ri β€ 2 Γ 104
- 1 β€ ci β€ 1000
- The segments in coins are non-overlapping