Nearby Fulfillment Centers with Inventory
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Amazon OA from July 2025 looks like a graph problem dressed up as logistics, and the first attempt usually dies on a small detail. You're asked to find fulfillment centers within maxStep edges of a destination that still have stock. It's a breadth-first search with a filter on top. If you've got an OA invite and 48 hours, this is one to nail cleanly. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the logic below is short enough to hold in your head.
The problem
A delivery must be fulfilled near a destination center. The fulfillment network is an undirected graph whose edges are given by connections. Each row [u, v] connects centers u and v in both directions. The array inventory represents a map from center ID to available quantity: each row is [centerId, quantity], and every center ID appears exactly once. Return every center ID that satisfies all of these conditions: the center is not destination; its inventory quantity is greater than 0; its shortest-path distance from destination is at most maxStep edges. Return the qualifying IDs in ascending numerical order. A center in a disconnected component does not qualify. Function findFulfillmentCenters(connections: int[][], destination: int, maxStep: int, inventory: int[][]) → int[] Examples Example 1 connections = [[1,2],[1,3],[2,4],[3,4],[4,5]] destination = 4 maxStep = 1 inventory = [[1,2],[2,0],[3,5],[4,3],[5,6]] return = [3,5] Centers 2, 3, and 5 are one edge from destination 4. Center 2 has no inventory, while centers 3 and 5 have positive inventory. The destination itself is excluded. Example 2 connections = [[10,20],[20,30],[30,40]] destination = 20 maxStep = 2 inventory = [[10,1],[20,9],[30,0],[40,4],[50,8]] return = [10,40] Center 10 is one edge away and center 40 is two edges away. Center 30 has zero inventory, and center 50 is disconnected. Example 3 connections = [[1,2],[2,3]] destination = 2 maxStep = 0 inventory = [[1,7],[2,5],[3,9]] return = [] With maxStep = 0, only the destination is at an allowed distance, and the destination must be excluded. Constraints 1 <= inventory.length <= 2 * 10^5. Each inventory[i] is [centerId, quantity]; center IDs are distinct positive integers, and 0 <= quantity <= 10^9. destination appears exactly once in inventory. 0 <= connections.length <= 2 * 10^5; each row contains two distinct center IDs that both appear in inventory. 0 <= maxStep <= 2 * 10^5. The graph may be disconnected, and the answer is returned in ascending numerical order.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build an adjacency list from connections, then run BFS from destination, tracking distance per node. Stop expanding once distance reaches maxStep. Collect any node that isn't the destination, has quantity above 0, and was reached within the limit. Sort the result ascending. The pitfall that sinks first attempts is the destination. With maxStep = 0 it's the only reachable node and it must be excluded, as Example 3 shows. Other traps: building the adjacency from inventory IDs that have no edges, so isolated centers like 50 never get visited, and using DFS, which gives wrong shortest distances. Use a hash map for inventory lookups since IDs aren't contiguous. Complexity is O(V + E + k log k) with up to 2 * 10^5 of each, so recursion depth is a risk too. Go iterative with a queue. If you freeze on the OA, StealthCoder can surface this BFS template while you verify the edge cases.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Nearby Fulfillment Centers with Inventory cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Nearby Fulfillment Centers with Inventory FAQ
What's the trick in the Amazon nearby fulfillment centers problem?+
It's a plain BFS from the destination with a depth cap at maxStep. The filtering is the only twist: skip the destination, require quantity above 0, and sort the output. Nothing exotic, so the points are in clean edge-case handling.
Why does maxStep = 0 return an empty list?+
At zero steps the only center at an allowed distance is the destination itself, and the rules exclude it. So no center qualifies. Example 3 tests exactly this, and it's the most common first-attempt bug.
Should I use BFS or DFS here?+
BFS. You need shortest-path distance in an unweighted graph, and BFS gives that level by level. DFS can reach a node by a longer path first and mislabel its distance, which breaks the maxStep check.
How do I handle disconnected centers?+
BFS only visits nodes connected to the destination, so disconnected centers are never reached and never added. You don't need extra logic. Just make sure unreached nodes aren't included by looping over inventory instead of the visited set.
How do I prepare for this in 48 hours?+
Write a BFS with an adjacency list and a distance map from memory twice. Then add the filter and sort. Test the three given examples plus a case with an isolated center and a case with zero stock everywhere. That covers it.