Find Maximum Money
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 (109 + 7).
Function Description
Complete the function findMaximumMoney
in the editor below.
findMaximumMoney has the following parameters:
int k
: the number of consecutive bags you will take.int segment[n][3]
: A 2D array where n is the number of segments. Each segment contains the start index, end index, and money in the bags for that range.
Returns
int
: the amount of money inside the k consecutive bags with the maximum total amount of money modulo 109 + 7.

Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.