Calculate Total Distrance Travelled
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's distance calculation problem landed in September 2024 assessments, and it's a straightforward simulation that catches people off guard because they overthink it. You're given coordinates or movement data and need to sum up the total distance traveled. No dynamic programming tricks, no graph shortcuts. It's math and iteration, which means you can solve it in under 10 minutes if you nail the formula. StealthCoder sits ready as your safety net if you blank on how to handle edge cases or coordinate systems during the live OA.
Pattern and pitfall
This is pure coordinate geometry wrapped in simulation. You'll likely receive a sequence of points or positions and calculate distance between consecutive points using the Euclidean distance formula (or Manhattan distance depending on the problem variant). The trick is recognizing that you're not finding shortest path or optimization, just accumulating distances. The gotcha: floating-point precision, off-by-one errors on array iteration, and forgetting to handle the starting position. Most candidates nail the core math but miss initialization or boundary cases. If you're stuck mid-OA, StealthCoder catches the formula and the iteration pattern instantly.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Calculate Total Distrance Travelled cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Calculate Total Distrance Travelled FAQ
Is this a shortest-path or optimization problem?+
No. You're summing distances between consecutive points in the given sequence. No pathfinding, no greedy selection. Just accumulate and return the total. Don't hunt for a trick that isn't there.
What distance formula does Amazon usually expect?+
Check the problem statement for whether it's Euclidean (sqrt of sum of squared differences) or Manhattan (sum of absolute differences). The problem text will be explicit. Default to Euclidean unless told otherwise.
What's the common pitfall?+
Forgetting to handle the starting position correctly, off-by-one errors in your loop, and floating-point rounding. Test with a three-point example on paper first. One point means zero distance traveled.
Can I solve this in under 10 minutes?+
Yes, easily. Write the distance formula, loop through consecutive pairs, accumulate, return. If you're spending more than 8 minutes, you're overthinking it. That's your signal to step back.
Is this problem still asked in 2024?+
Yes. Amazon favors simulation and math problems for OAs. Coordinate geometry and distance calculation are stable across their assessments. Expect it to remain a common variant.