Cheapest Charging Plan for an Electric Delivery Van Route

Last updated: November 29, 2026

Quick Overview

An electric delivery van starts empty at a depot and must reach a destination city over roads that consume battery equal to their length. Each city sells charge at its own price per unit and the battery holds at most C units; return the minimum charging cost, or -1 if unreachable.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


An electric delivery van starts empty at a depot and must reach a destination city over roads that consume battery equal to their length. Each city sells charge at its own price per unit and the battery holds at most C units; return the minimum charging cost, or -1 if unreachable.

Amazon's electric van fleet makes charging strategy a real routing concern. The interviewer is testing whether you expand the state to (city, battery level) and run Dijkstra on that graph, instead of greedily charging to full everywhere.

What the Interviewer Expects
  • Explain why city alone is not a sufficient state
  • Model actions as charge one unit or drive a road
  • Run Dijkstra over (city, fuel) states with cost as the key
  • Bound the state space by n * (C + 1)
  • Return when the destination is popped with any fuel level
Key Topics to Cover
Dijkstra
state-space search
weighted graphs
resource constrained shortest path
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 speed this up when C is large, for example by charging only to amounts that matter?
  • What if each charger has a fixed stop fee plus a per-unit price?
  • How would you add a limit on the number of charging stops?
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

Input: n cities, undirected roads (u, v, d) with integer length d, a list price[i] per unit of charge, capacity C, src and dst. The van starts with 0 charge at src. Driving a road needs ...

High-Level Design

Build a graph whose nodes are states (city, fuel) for fuel 0..C. From each state there are two kinds of moves: buy one unit at price[city] (to (city, fuel + 1) if fuel < C), or drive a road of l...


Submit Your Answer
Markdown supported