Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Maximum Money in Consecutive Bags
00:00
5 left

Maximum Money in Consecutive Bags

MediumSQL · PostgreSQL

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
Interviewer

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

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.