First Waypoint Where Return-to-Hub Battery Reserve Breaks
Last updated: November 29, 2026
Quick Overview
Given a drone's starting charge, the energy for each outbound leg of a multi-stop route, the energy to fly each leg in reverse, and a required landing reserve, return the first waypoint at which the aircraft could no longer fly home with the reserve intact, or -1 if the route is safe.
Zipline
November 29, 20260
0
0 solved
Given a drone's starting charge, the energy for each outbound leg of a multi-stop route, the energy to fly each leg in reverse, and a required landing reserve, return the first waypoint at which the aircraft could no longer fly home with the reserve intact, or -1 if the route is safe.
A warm-up in the style of Zipline's phone screens, where coding prompts are framed around flight operations. The interviewer is checking that you can turn a safety rule (always be able to return home with reserve) into a single linear pass with clean prefix sums and no off-by-one errors.
What the Interviewer Expects
- Restate the safety invariant precisely before coding
- Notice that return cost and outbound cost are different because of wind
- Use running sums for a single O(n) pass
- Decide and state whether waypoints are 0- or 1-indexed
- Handle an empty route and mismatched list lengths
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the furthest safe waypoint and the margin at each stop instead?
- What changes if the drone can divert to any of several alternate landing sites, not just the hub?
- How would you model energy that depends on payload weight dropping after each delivery?
- If leg energies are noisy estimates, how would you build in a confidence margin?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: charge (percent), out_legs[i] energy to fly leg i outbound, back_legs[i] energy to fly the same leg in reverse (headwind and tailwind make these differ), and reserve. After arriving at...
High-Level Design
Keep two running totals: energy used so far outbound, and the energy to retrace every leg flown so far. Both grow by one leg per step, so each check is O(1). The first violation is the answer because ...