HARDasked at 1 company

Minimum Total Distance Traveled

A hard-tier problem at 59% community acceptance, tagged with Array, Dynamic Programming, Sorting. Reported in interviews at Infosys and 0 others.

Founder's read

You're given a list of robots and a list of factory positions. The task is to assign each robot to exactly one factory such that the total distance traveled is minimized. This problem sits at the intersection of assignment and optimization, and it's harder than the straightforward greedy approach suggests. The acceptance rate hovers around 59%, which means nearly half the candidates who attempt it walk away empty-handed. Infosys has reportedly asked this one. If you hit it during a live assessment and your first instinct doesn't pan out, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
59%

Companies that ask "Minimum Total Distance Traveled"

If this hits your live OA

Minimum Total Distance Traveled is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The trap is thinking you can just pair nearest robot to nearest factory. The real solution requires dynamic programming after sorting both arrays. You sort robots and factories by position, then build a DP table where the state tracks which robots and factories you've already assigned. The key insight: once you sort, the optimal assignment respects that order, so you never cross assignments. This is a classic DP optimization problem where the state space collapses once you recognize the sorted property. Most candidates either skip sorting altogether or try greedy matching and get stuck on test cases where greedy fails. If you haven't drilled this pattern before, the jump from 'sort both lists' to 'DP on assignment indices' isn't obvious under time pressure. StealthCoder handles the full DP setup and recurrence if you blank during the live OA.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Minimum Total Distance Traveled recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Total Distance Traveled interview FAQ

Why doesn't greedy (match closest pairs) work here?+

Greedy can violate the global optimum because pairing a robot to its nearest factory might block a better overall assignment for other robots. Once sorted, the DP enforces non-crossing assignments, which greedy ignores. You need to compute all valid orderings.

Is this really asked at big companies?+

Infosys has reported it. It's a solid hard-tier problem, so expect it at mid-to-large tech companies that value DP skills. The 59% acceptance rate suggests it's not super common, making it a good hedge to know.

What's the time complexity and how does it compare to greedy?+

DP solution is O(n^2) after sorting. Greedy is O(n log n) but wrong. The DP cost is justified because the state space shrinks dramatically once you sort both arrays and recognize that optimal assignments never cross.

How does this differ from the standard assignment problem?+

Standard assignment (Hungarian algorithm) is general and applies to any cost matrix. Here, the 1D sorted structure lets you use DP instead, making it much simpler to code under time pressure and easier to derive during the interview.

What do I need to know about Dynamic Programming to solve this?+

You need to understand DP table construction where state is (robot index, factory index) and recurrence explores assigning the current robot to the current or a future factory. Sorting and memoization are critical to avoiding exponential blowup.

Want the actual problem statement? View "Minimum Total Distance Traveled" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.