Minimum Charging Stops for an Autonomous Delivery Vehicle Route

Last updated: November 29, 2026

Quick Overview

An autonomous delivery vehicle must travel target_km along a fixed route starting with some range, passing chargers at known positions that each add a fixed amount of range. Return the minimum number of charging stops to reach the destination, or -1.

Applied Intuition
Coding & Algorithms
Software Engineer
Applied Intuition
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


An autonomous delivery vehicle must travel target_km along a fixed route starting with some range, passing chargers at known positions that each add a fixed amount of range. Return the minimum number of charging stops to reach the destination, or -1.

Applied Intuition's autonomy work spans trucking, mining and delivery, where route energy planning is a natural framing. The interviewer checks the greedy with a max-heap of passed chargers and a proof that retroactively choosing the largest one is optimal.

What the Interviewer Expects
  • Recognize that a DP over stops works but is O(n^2)
  • Push every charger within current reach into a max-heap
  • When stuck, take the largest passed charger and count a stop
  • Return -1 when the heap empties before reaching the target
  • Justify the greedy with an exchange argument
Key Topics to Cover
greedy
heaps
exchange argument
route planning
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you return which chargers were used?
  • What if charging time differs per charger and you minimize total trip time?
  • What if battery capacity is capped so charge cannot exceed a maximum?
  • How would you handle a graph of routes instead of a single line?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

chargers is a sorted list of (position_km, range_km). The vehicle has unlimited battery capacity, so added range stacks. Reaching a charger exactly at the edge of range is allowed. Return the mini...

High-Level Design

Think of driving as far as possible and deciding afterward where to have stopped. Every charger within reach is a candidate. When reach is short of the target, the best single stop to add is the one w...


Submit Your Answer
Markdown supported