Reported September 2026
Amazonhash table

Initial and Final Accounts in a Transfer Chain

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The Amazon OA from September 2026 dresses up a tiny idea in a long story about transfer chains. Strip the story and it's a set difference. You get shuffled [from, to] pairs and need the one account nobody sends money to, and the one that never sends. If you're taking this in a day or two, don't build the chain. You don't need to. And if your brain locks up mid-assessment, StealthCoder runs invisibly on your desktop and hands you the approach as a safety net.

The problem

You are given directed account-transfer pairs [from, to] in arbitrary order. Together they form one non-branching chain containing every pair exactly once.
Return [initialAccount, finalAccount], where the initial account has no incoming transfer and the final account has no outgoing transfer.

Function
transferEndpoints(transfers: int[][]) → int[]

Examples
Example 1
transfers = [[222,111],[111,333],[444,222]]
return = [444,333]
The complete chain is 444 to 222 to 111 to 333.
Example 2
transfers = [[1,2]]
return = [1,2]
A one-transfer chain exposes both endpoints directly.
Example 3
transfers = [[3,4],[1,3],[4,8]]
return = [1,8]
Input order does not affect the recovered endpoints.

Constraints
1 ≤ transfers.length ≤ 100000.
Every transfer contains two distinct integer account IDs.
The pairs form exactly one acyclic chain with no branches.

Reported by candidates. Source: FastPrep

Pattern and pitfall

What the problem really reduces to: count each account's role. The initial account appears as a sender but never as a receiver. The final account appears as a receiver but never as a sender. Put every 'from' in one hash set and every 'to' in another. Then scan for the 'from' not in the 'to' set, and the 'to' not in the 'from' set. That's O(n) time and O(n) space, fine for 100000 pairs. The common pitfall is sorting the pairs or linking them into a path, which costs more and invites bugs. Another trap is assuming IDs are small or ordered. They're arbitrary integers, so use hash sets, not arrays indexed by ID. With one pair, the same logic still works. If you freeze on the live OA, StealthCoder is the hedge that surfaces this set-difference approach quickly.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Initial and Final Accounts in a Transfer Chain 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 StealthCoder

Related leaked OAs

⏵ The honest play

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.

Initial and Final Accounts in a Transfer Chain FAQ

What's the trick in the Amazon transfer chain problem?+

Don't reconstruct the chain. The start is the only account that appears as a sender and never as a receiver. The end is the only one that appears as a receiver and never as a sender. Two hash sets and one pass each gets you both endpoints.

How hard is this problem really?+

Easy once you see it. The story is longer than the solution. The risk is overthinking it with graph traversal or sorting. If you catch the set-difference idea in the first minute, the code is about ten lines.

What's the time complexity I should aim for?+

O(n) time and O(n) space. With up to 100000 transfers, an O(n log n) sort would pass too, but it's unnecessary. Hash sets of senders and receivers give you the answer in a single linear pass plus a lookup scan.

Can I solve it with a single pass and no sets?+

Yes. Keep a hash map of counts where a sender adds one and a receiver subtracts one. The start ends at +1 and the end at -1. Every middle account nets to zero. Scan the map for those two values.

How do I prep for this in 48 hours?+

Practice degree-counting and set-difference patterns on arrays of pairs. Write the two-set version and the net-count version from memory. Test edge cases like a single transfer and reversed input order. That covers the variations an assessment is likely to throw.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it