Lowest Total Fee Crossing Paid Checkpoints One or Two at a Time
Last updated: November 29, 2026
Quick Overview
A delivery robot moves along a line of checkpoints, each with a toll, and may advance one or two checkpoints per move, starting before the first or second checkpoint. Return the minimum total toll to get past the last checkpoint.
0
0
0 solved
A delivery robot moves along a line of checkpoints, each with a toll, and may advance one or two checkpoints per move, starting before the first or second checkpoint. Return the minimum total toll to get past the last checkpoint.
A common early question in Google technical screens because it tests whether you can define a DP state precisely rather than memorize an answer. Interviewers look for the right base cases and an O(1) space version.
What the Interviewer Expects
- Define cost[i] as the cheapest way to stand on checkpoint i having paid its toll
- Handle the two possible starting positions as base cases
- Answer is the cheaper of the last two states
- Reduce memory to two rolling variables
- Trace a small example aloud
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 the robot can jump up to k checkpoints at a time?
- Return the actual checkpoints visited, not just the cost.
- What if some tolls are negative (rebates)?
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: a list toll of non-negative integers, length n >= 2. The robot pays toll[i] when it lands on checkpoint i. It can start on checkpoint 0 or 1 for free (paying that checkpoint's toll) and fin...
High-Level Design
Let best[i] be the minimum toll paid when the robot stands on checkpoint i. It arrived from i - 1 or i - 2, so best[i] = toll[i] + min(best[i-1], best[i-2]), with best[0] = toll[0] and `best[1] ...