FastPrepCompute Walking Distance
Problems/Compute Walking Distance

Compute Walking Distance

TikTok logoTikTok● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamples

Problem statement

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 p to p + 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.

Function

computeWalkingDistance(target: int, stations: int[]) → int

Examples

Example 1

target = 15stations = [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.

Example 2

target = 25stations = [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 interview questions

  • Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
  • Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
  • Count Subarrays with at Least K Equal-Fruit PairsOA · Seen Oct 2026
  • Shell Command Counts with History ReferencesOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Sep 2026
  • Product Minus Sum of DigitsOA · Seen Aug 2026
  • Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
  • Find All Local PeaksOA · Seen Aug 2026
  • Count Case-Insensitive TripletsOA · Seen Aug 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
  • Server ManagementRippling · OARippling interview questions
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
  • Economical TripAccenture · OAAccenture interview questions
  • Minimum Pile Reduction StepsAmerican Express · OAAmerican Express interview questions
  • Find Maximum Number of Subjects Passed (AS Intern, but it may apply to other interns) 🍋Amazon · OA
  • Maximum Production Within PowerZomato / Eternal · OAZomato / Eternal interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions

TikTok interview experiences

  • TikTok AI Infra Intern LLM Round 2: 1 Experience
  • TikTok AI Infra Intern DeepSpeed Round: 1 Experience
  • TikTok AI Infra Intern Kernel Round: 1 Experience
  • TikTok AI Infra Intern Interviews, 3 Rounds: 1 Experience
  • TikTok AI Infra Intern Interview Timeline: 1 Experience
  • TikTok AI Infra Intern Onsite Round 2: 1 Experience
All TikTok interview questionsSee TikTok hiring insights
Saved
class Solution {
    public int computeWalkingDistance(int target, int[] stations) {
      // write your code here
    }

}
Checking account…