Back to problems

Max Money from K Consecutive Bags

Algorithm · Amazon · Medium

Requirements k specifies how many adjacent bag positions must be selected. segment[n][3] contains entries of the form [start, end, money]. Every position from start through end, including both endpoints, contains money. Any position that belongs to no segment contains 0. Consider the bags arranged along a number line. Choose any k consecutive positions and return the largest possible sum of their contents. Examples The window from positions 3 through 7 is optimal, because…

Checking your access…