Linear Warehouse Drone Delivery
Learn this problemProblem statement
Source note (2026-08-04): The visible source provides the complete delivery protocol, required result, complexity target, and one example. It omits exact numeric bounds and the complete callable signature. The judged core task matches the visible source at about 97%.
You are designing a delivery system that uses drones in a linear warehouse. The warehouse is a number line that starts at position 0 and ends at position target, where target > 0.
Charging stations are placed at positions given by the array stations. A fully charged drone can carry the cargo at most 10 units to the right. For example, a drone launched at position 12 can reach any position through 22, inclusive, but cannot reach position 23.
Starting with the cargo at position 0, repeat this protocol until the cargo reaches target:
- Carry the cargo on foot from its current position to the nearest charging station at or ahead of that position. If there is no such station before the target, carry the cargo directly to
target. - Launch a fully charged drone from that station and send the cargo as far as possible toward
target, up to10units. - If the target has not been reached, walk to the position where the drone landed, retrieve the cargo, and repeat.
Return the total distance over which the cargo is carried on foot. Walking performed without the cargo is not included.
A solution with time complexity no worse than O(stations.length * target) fits within the execution time limit.
Function
minimumFootDistance(target: int, stations: int[]) → intExamples
Example 1
target = 23stations = [7,4,14]return = 4Carry the cargo from 0 to station 4, adding 4. The drone carries it to 14. A drone can launch immediately from the station at 14 and reach 23, so no more cargo-carrying on foot is needed.
Example 2
target = 25stations = [20,10,0]return = 0The cargo begins at station 0. Drones launched from stations 0, 10, and 20 carry it all the way to the target, so the cargo is never carried on foot.
Example 3
target = 28stations = [25,3]return = 15Carry the cargo 3 units to station 3, then the drone carries it to 13. Carry it another 12 units to station 25, whose drone reaches the target. The total is 3 + 12 = 15.
Constraints
target > 0.- Every value in
stationsis a position on the warehouse line from0throughtarget. - The answer fits in a signed 32-bit integer.
More Tiktok problems
- Count Access Code PairsOA · Seen Aug 2026
- Count Case-Insensitive TripletsOA · Seen Aug 2026
- Distribution Center Package AllocationOA · Seen Aug 2026
- Optimize TikTok Reels ViewingOA · Seen Aug 2026
- Can Reach the Exit with TeleportsOA · Seen Jul 2026
- Check Monotonic TriplesOA · Seen Jul 2026
- Shift Every K-th ConsonantOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026