Cheapest Way to Move a Tote Down a Conveyor With Short Hops
Last updated: November 29, 2026
Quick Overview
A tote moves along conveyor stations where landing on station i costs cost[i]; it may enter at station 0 or 1 and from any station hop forward one or two stations. Return the minimum cost to move past the last station.
Amazon
November 29, 20260
0
0 solved
A tote moves along conveyor stations where landing on station i costs cost[i]; it may enter at station 0 or 1 and from any station hop forward one or two stations. Return the minimum cost to move past the last station.
Amazon fulfillment conveyors route totes through sorters and stations, and this easy phone screen DP models the cost of each stop. The interviewer checks the base cases and that you can explain the recurrence before coding.
What the Interviewer Expects
- Define best cost to land on each station
- Recurrence: land(i) = cost[i] + min(land(i-1), land(i-2))
- Answer is min of the last two landings
- Roll to O(1) space
- Handle one or two stations
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if hops of up to k stations are allowed?
- What if some stations are closed?
- How would you print the stations used?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list cost of non-negative integers. The tote starts before the conveyor and can enter at station 0 or 1; it ends once it hops beyond the last index. Output: minimum total cost....
High-Level Design
Let land(i) be the cheapest total cost if the tote lands on station i. To land on i it came from i-1 or i-2 (or entered directly at 0 or 1, cost 0 before landing). So `land(i) = cost[i] + min(land(i...