Nearby Fulfillment Centers with Inventory
Updated
Problem statement
A delivery must be filled from a center near a destination center. The fulfillment network is made of centers and links. The array connections lists the links. Each row [u, v] links centers u and v, and a link can be used in both directions.
The array inventory gives the available quantity at each center. Each row is [centerId, quantity], and every center ID appears in exactly one row.
Return the ID of every center that meets all of these rules:
- It is not
destination. - Its inventory quantity is greater than
0. - The fewest links needed to go from
destinationto it is at mostmaxStep.
Return the matching IDs sorted from smallest to largest. A center that cannot be reached from destination at all never qualifies.
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 = 4maxStep = 1inventory = [[1,2],[2,0],[3,5],[4,3],[5,6]]return = [3,5]Centers 2, 3, and 5 are one link from destination 4. Center 2 has no inventory, so it is left out. Centers 3 and 5 both have stock, so they qualify. The destination itself never counts, so the answer is these two centers.
Example 2
connections = [[10,20],[20,30],[30,40]]destination = 20maxStep = 2inventory = [[10,1],[20,9],[30,0],[40,4],[50,8]]return = [10,40]Center 10 is one link away and center 40 is two links away. Both have stock, so they qualify. Center 30 has zero inventory, and center 50 cannot be reached at all, so neither counts. The destination itself is left out.
Example 3
connections = [[1,2],[2,3]]destination = 2maxStep = 0inventory = [[1,7],[2,5],[3,9]]return = []With maxStep = 0, no link may be used, so only the destination itself is close enough. The destination is always left out, so the answer is empty.
Constraints
1 <= inventory.length <= 2 * 10^5.- Each
inventory[i]is[centerId, quantity]. Center IDs are distinct positive integers. 0 <= quantity <= 10^9.destinationappears exactly once ininventory.0 <= connections.length <= 2 * 10^5.- Each row of
connectionsholds two different center IDs. Both appear ininventory. 0 <= maxStep <= 2 * 10^5.- Some centers may not be reachable from others. The answer is sorted from smallest to largest.
More Amazon Onsite Interview questions
- 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 SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Optimal Account BalancingONSITE INTERVIEW · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Shortest Path Node Count Avoiding Broken NodesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Minimum Friend API CallsMercor · ONSITE INTERVIEWMercor interview questions
- Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
- Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Open the Lock and Return a Shortest PathZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
- Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
- Shortest Path from an Encoded GraphIntuit · OAIntuit 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)