Minimum E-Bike Battery Range for a Delivery Route

Last updated: November 29, 2026

Quick Overview

A GrabFood rider on an e-bike travels a straight route of length `dest` km starting fully charged, with swap stations at given km marks where the battery can be swapped to full. Find the minimum integer battery range so the rider reaches the end using at most `k` swaps.

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

0

0

0 solved


A GrabFood rider on an e-bike travels a straight route of length `dest` km starting fully charged, with swap stations at given km marks where the battery can be swapped to full. Find the minimum integer battery range so the rider reaches the end using at most `k` swaps.

Grab has pushed electric two-wheelers for delivery partners, and battery swap planning is a natural setting for a binary search on the answer question. The interviewer wants a monotonic feasibility check, a correct greedy inside it, and tight reasoning about why both are right.

What the Interviewer Expects
  • Notice that feasibility is monotonic in battery range
  • Binary search the range between 1 and the route length
  • Write a greedy check that swaps at the farthest reachable station
  • Prove the greedy minimizes swaps for a given range
  • Handle unreachable gaps and duplicate or out-of-range stations
Key Topics to Cover
Binary search on answer
Greedy
Monotonic predicate
Interval jumping
Proof of optimality
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
  • Can you solve it without binary search, directly from the gaps?
  • What if swaps have different costs at different stations and you minimize total cost?
  • What if the battery range is a real number rather than an integer?
  • How would you extend this when the route is a graph instead of a 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

Route from km 0 to km dest, stations at integer positions, battery full at the start and after each swap, at most k swaps. Find the smallest integer range C that works. Stations at 0, at dest ...

High-Level Design

If range C works, any larger range also works, so the predicate swaps_needed(C) <= k is monotonic and we can binary search C in [1, dest]; C = dest always works with zero swaps. For a fixed ...


Submit Your Answer
Markdown supported

Related Questions