Loading...
You are given a 2D array segments, where segments[i] = [l_i, r_i, v_i] means every integer position from l_i to r_i (inclusive) carries the value v_i. The segments are non-overlapping, and positions outside every segment carry 0.
You are also given an integer k. Choose k consecutive integer positions and collect the values of all of them.
Return the maximum total value you can collect.
Input: segments = [[8,10,1],[1,3,2],[5,6,4]], k = 4
Output: 10
Explanation: Positions 3, 4, 5, 6 collect 2 + 0 + 4 + 4 = 10.
Input: segments = [[1,10,3]], k = 2
Output: 6
segments.length ≤105Click "Run" to test with sample cases or "Submit" to run all tests.