Find Maximum Total Amount (SDE I, Fungible :)
In Amazon's financial team, an analyst is dealing with an infinite number of bags arranged in a line, each numbered from 1 to infinity. The task is to gather information about the amount of money in these bags, presented in the form of continuous segments. The objective is to select consecutive bags in such a way that the total amount of money in these bags is maximized.
The continuous segments provided to represent the amount of money in each bag do not intersect. Additionally, any bag included within a segment contains some amount of money, while bags not included in any segment are considered to have zero money.
Formally, given a 2D array segment of size n x 3, where n represents the number of available segments, and an integer k representing the number of consecutive bags you will take, and the 2D array segment represents the range of bags included in this segment [segment[0], segment[1]] and the amount of money inside the bags in the range segment[2].
Find the k consecutive bags with the maximum total amount of money, since the answer can be large, return it modulo (10^9 + 7).
Complete the function maxTotalAmount in the editor.
maxTotalAmount has the following parameters:
- 1.
int[][] segment: a 2D array where each element is an array of three integers representing the range of bags and the amount of money - 2.
int k: the number of consecutive bags
Returns
int: the maximum total amount of money in k consecutive bags, modulo (10^9 + 7)
⸜(。˃ ᵕ ˂)⸝♡ Feeling so lucky to have spike's help~~
1Example 1

Constraints
Limits and guarantees your solution can rely on.
🍑🍑