Farthest Checkpoint a Sidewalk Delivery Robot Reaches on Limited Battery

Last updated: November 29, 2026

Quick Overview

A sidewalk delivery robot moves through checkpoints with elevations heights[0..n-1]. Going downhill or flat is free; a climb of d costs d battery units or one boost charge. Given battery units and boost charges, return the farthest checkpoint index it can reach.

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

0

0

0 solved


A sidewalk delivery robot moves through checkpoints with elevations heights[0..n-1]. Going downhill or flat is free; a climb of d costs d battery units or one boost charge. Given battery units and boost charges, return the farthest checkpoint index it can reach.

An Uber onsite heap question with a framing from Uber Eats robot delivery pilots. Interviewers look for the insight that boosts should be saved for the largest climbs, maintained greedily with a min-heap as the robot advances.

What the Interviewer Expects
  • Notices that only positive climbs matter
  • Keeps the climbs covered by boosts in a min-heap of size at most boosts
  • When the heap overflows, pays the smallest boosted climb with battery instead
  • Stops at the first checkpoint where battery would go negative
  • Argues why the greedy is optimal and gives O(n log b) time
Key Topics to Cover
heaps
greedy
min-heap
exchange argument
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
  • Return the minimum battery needed to reach the last checkpoint with b boosts.
  • What if boosts recharge after every 10 checkpoints?
  • How would you answer the same question for many (battery, boosts) pairs?
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: list heights, integers battery >= 0, boosts >= 0.
  • Output: largest index reachable from index 0.
  • Each climb between consecutive checkpoints is paid fully by battery or by exactly one...
High-Level Design

Walk forward. For each positive climb, tentatively cover it with a boost by pushing it onto a min-heap. If the heap now holds more climbs than there are boosts, the cheapest boosted climb should be pa...


Submit Your Answer
Markdown supported