Minimum Battery Swaps for an E-Bike Dasher Route

Last updated: November 29, 2026

Quick Overview

An e-bike Dasher starts with a full battery and must reach a destination over roads that each consume some charge; at swap stations they can replace the battery to full. Return the minimum number of swaps needed, breaking ties by least total charge used.

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

0

0

0 solved


An e-bike Dasher starts with a full battery and must reach a destination over roads that each consume some charge; at swap stations they can replace the battery to full. Return the minimum number of swaps needed, breaking ties by least total charge used.

Dashers in dense cities deliver on e-bikes, and range planning is a real concern. This shortest path question checks whether you expand the state to (node, charge left), use Dijkstra with a lexicographic cost, and prune states carefully. It is a step up from plain Dijkstra that DoorDash onsites like to use as the hard problem.

What the Interviewer Expects
  • Recognize that node alone is not enough state
  • Model a swap as a zero-distance edge that costs one swap
  • Use a lexicographic cost (swaps, charge used) in the heap
  • Discard roads that exceed full battery capacity
  • Discuss state space size and dominance pruning
Key Topics to Cover
shortest paths
Dijkstra
state space search
weighted graphs
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 add travel time and minimize arrival time with swaps taking 3 minutes each?
  • How would you prune states that are dominated (same node, more charge, same or lower cost)?
  • What if stations can run out of charged batteries?
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
  • n nodes, undirected roads (u, v, charge), a set of swap stations, src, dst, capacity.
  • Start full. Traversing a road needs at least its charge remaining.
  • At a station, a swap resets cha...
High-Level Design

The state is (node, charge_left). Push (swaps, used, node, charge) into a min-heap so Python compares swaps first, then used. On pop, skip states already settled with an equal or better cost. From...


Submit Your Answer
Markdown supported