FastPrepMaximum Earnings Across Warehouses
Problems/Maximum Earnings Across Warehouses

Maximum Earnings Across Warehouses

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionExamples

Problem statement

Source note: Reported in November 2026 from an Amazon Software Development Engineer II interview loop in India, as the coding question of the second of four interview rounds. A driver goes along a row of warehouses, and each one either pays money or charges a toll. The trip has to begin at the first warehouse and finish at the last one, no more than k warehouses in a row may be passed over between two stops, and the goal is the largest total.

The report gave these rules and one list of values with k = 3, but no answer, no input format and no limits. We worked out the answer for that list (50) and use it as Example 1, added two examples of our own, and chose the limits (up to 10^5 warehouses, values from -10^4 to 10^4, k below the number of warehouses). The values and k are passed to a function.

Our version is about 95% the same as the reported question.

A driver passes n warehouses in a fixed order, numbered 0 to n - 1. Stopping at warehouse i changes the driver's total by values[i]: a positive value is money earned there, and a negative value is a toll or cost paid there.

The driver picks the warehouses to stop at:

The problem statement continues
Pro

Examples

Example 1

values = [100,-30,-50,-50,-20,-30]k = 3return = 50

Stop at warehouses 0, 4 and 5: 100 + (-20) + (-30) = 50. Going from 0 to 4 skips warehouses 1, 2 and 3, three in a row, which k = 3 allows. The driver cannot go from 0 straight to 5, because that skips four. So at least one of warehouses 1 to 4 is a stop, and -20 is the smallest cost among them.

02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

More Amazon Onsite Interview questions

  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
  • Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
  • Longest Continuous Subarray Within an Absolute-Difference LimitUber · ONSITE INTERVIEWUber interview questions
  • Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
  • Bad Request AlertsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Fixed-Window Rolling MeanJump Trading · ONSITE INTERVIEWJump Trading interview questions
  • Sliding Window MaximumPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Sliding Window MaximumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Sliding Window Average (Meta Canada, E4/E5 :)Meta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Disk Space Window AnalyzerAgoda · PHONE SCREENAgoda interview questions

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week