Problem · Array

Linear Warehouse Drone Delivery

Learn this problem
EasyTiktok logoTiktokINTERNOA
See Tiktok hiring insights

Problem 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:

  1. 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.
  2. Launch a fully charged drone from that station and send the cargo as far as possible toward target, up to 10 units.
  3. 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[]) → int

Examples

Example 1

target = 23stations = [7,4,14]return = 4

Carry 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 = 0

The 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 = 15

Carry 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 stations is a position on the warehouse line from 0 through target.
  • The answer fits in a signed 32-bit integer.

More Tiktok problems

drafts saved locally
public int minimumFootDistance(int target, int[] stations) {
    // write your code here
}
target23
stations[7,4,14]
expected4
checking account