Starting from position 0, you need to carry cargo to a target position. Along the way there are charging stations at various positions. The process works as follows:
- Walk with the cargo to the nearest charging station ahead of your current position.
- Use a drone at that station to carry the cargo forward by 10 units (i.e., from station position
ptop + 10). - Repeat until the cargo reaches or passes the target.
- If no station is ahead, walk the remaining distance on foot.
Compute the total distance you actually carry the cargo on foot (excluding drone-traveled parts).
Approach: Sort the stations. Each round, find the next usable station ahead of your current position, add the walking distance to reach it, then update your position to station + 10. Repeat until reaching or passing the target.
Examples
01 · Example 1
target = 15 stations = [5] return = 5
Walk from 0 to station 5 (5 units on foot). Drone carries cargo from 5 to 15. Position 15 >= target 15, done. Total walking distance = 5.
02 · Example 2
target = 25 stations = [5,20] return = 10
Walk from 0 to station 5 (5 units). Drone carries 5 → 15. Walk from 15 to station 20 (5 units). Drone carries 20 → 30. Position 30 >= target 25, done. Total walking = 5 + 5 = 10.
More Tiktok problems
- LRU Cache with TTL ExpirationONSITE INTERVIEW · Seen May 2026
- Maximum Candies with At Most Two Types in a LineONSITE INTERVIEW · Seen May 2026
- Top-K KOLs by Total LikesONSITE INTERVIEW · Seen May 2026
- Count Sawtooth SubarraysSeen Mar 2026
- Format TextSeen Mar 2026
- Memory AllocatorSeen Mar 2026
- TikTok Shopping SpreeSeen Mar 2025
- TikTok Video Relevance AdjustmentSeen Mar 2025
public int computeWalkingDistance(int target, int[] stations) {
// write your code here
}
target15
stations[5]
expected5
sign in to submit