FastPrepInitial and Final Accounts in a Transfer Chain
Problems/Initial and Final Accounts in a Transfer Chain

Initial and Final Accounts in a Transfer Chain

Amazon logoAmazon● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon SDE2 interview list with the account chain 444 to 222 to 111 to 333. Problem match confidence: approximately 96%.

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.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int[] transferEndpoints(int[][] transfers) {
        // write your code here
    }
}
Checking account…