Get Final Location
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon asked this in December 2024, and it's a simulation problem that looks easy until you miss an edge case. You're tracking position changes based on a sequence of commands, and the trick is handling invalid moves or boundary conditions without overthinking it. If you blank on the logic during the live OA, StealthCoder will catch the pattern and walk you through the state updates in real time.
Pattern and pitfall
This is a classic simulation where you maintain state (your current position) and apply transformations (commands) one at a time. The pattern is straightforward: iterate through commands, update coordinates, and return the final location. The catch is usually in how the problem defines valid moves, whether you skip invalid ones, or if there's a grid boundary. Most candidates over-engineer it. You don't need dynamic programming or complex data structures. Just track x and y, apply the command logic, and move on. If you get stuck in the OA, StealthCoder gives you the state machine approach to validate and update position cleanly.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Get Final Location 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as robot return to origin. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Get Final Location FAQ
Is this actually hard or just tedious?+
It's tedious, not hard. The difficulty is in parsing what 'invalid' means. Does the command get skipped, or do you hit an error? Read the problem twice. The trick is almost always in how invalid moves are handled, not the movement logic itself.
What's the time and space complexity?+
O(n) time where n is the number of commands. You iterate once. Space is O(1) because you only store two coordinates. No extra data structures needed unless the problem explicitly asks for a path history.
Do I need to worry about grid boundaries?+
Only if the problem statement says so. Read carefully. If it mentions a grid size or boundary, track it. Otherwise, assume unbounded space and just track position. Amazon usually specifies constraints explicitly.
How do I avoid off-by-one errors?+
Start at (0, 0) unless told otherwise. For each command, apply the transformation consistently. Test mentally: up moves y by 1, down by -1, etc. Write out the first three steps on paper before coding. It takes 30 seconds and saves you a resubmission.
What if there's a twist like multiple agents or rotations?+
The problem text would say so. If it mentions direction or rotation, you track facing as well as position. But 'Get Final Location' usually means simpler. Don't anticipate complexity that isn't in the statement.