Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Maximum Money in Consecutive Bags

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Maximum Money in Consecutive Bags. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Maximum Money in K Consecutive Bags: 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 as continuous segments. The objective is to select consecutive bags with the maximum total amount of money. Return the answer modulo 10^9 + 7.

Asked in the OA stage. The input is stored in continuous segments in bag_segments, with K set in the query.

Output

  1. Return one row with max_total_money.
  2. The value must represent the maximum total across exactly K consecutive bags, modulo 1,000,000,007.

Schema

bag_segments
ColumnTypeDescription
segment_idPKINTUnique identifier for the continuous segment
start_bagBIGINTFirst bag number in the segment
end_bagBIGINTLast bag number in the segment
money_per_bagBIGINTMoney contained in every bag in the segment
segment_labelVARCHAR(80)Optional descriptive label for the segment
Tablesbag_segments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results