Least Starting Battery to Finish Every Field Survey Task

Last updated: November 29, 2026

Quick Overview

A Street View field robot must complete every task once, in any order. Task i drains actual_i battery but can only start if the battery is at least minimum_i; return the least starting battery that allows finishing all tasks.

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

0

0

0 solved


A Street View field robot must complete every task once, in any order. Task i drains actual_i battery but can only start if the battery is at least minimum_i; return the least starting battery that allows finishing all tasks.

A scheduling greedy with a non-obvious sort key that Google onsite interviewers use to probe exchange-argument skills. They want the key minimum minus actual and a short proof, plus a clean way to compute the required start.

What the Interviewer Expects
  • Notice the battery is only checked before each task
  • Sort by minimum minus actual descending
  • Compute the required start by simulating with top-ups
  • Prove the order with an adjacent swap
  • O(n log n) time
Key Topics to Cover
Greedy
Exchange argument
Sorting
Simulation
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
  • Recharge stations restore some battery between tasks.
  • Some tasks must precede others.
  • Binary search on the starting battery: how would that work and what does it cost?
  • Minimize the battery left unused at the end.
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 of [actual, minimum] with actual <= minimum. Battery before task i must be >= minimum_i, and it drops by actual_i. Output: least starting battery to finish all tasks....

High-Level Design

Think of minimum - actual as the slack a task leaves: after doing it you still hold at least that much. Tasks with large slack should run first, when the battery is highest, because they 'give back'...


Submit Your Answer
Markdown supported