Trace Downstream Accounts Within K Transfer Hops

Last updated: November 29, 2026

Quick Overview

Given directed money transfers between accounts and one account flagged for fraud, return every account that received funds downstream of it within at most k hops, along with its minimum hop distance.

Capital One
Coding & Algorithms
Software Engineer
Capital One
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given directed money transfers between accounts and one account flagged for fraud, return every account that received funds downstream of it within at most k hops, along with its minimum hop distance.

Following money out of a compromised or mule account is a routine step in Capital One's fraud and anti-money-laundering investigations. As an assessment problem it checks that you pick breadth-first search for minimum hop counts, stop expanding at depth k, and avoid infinite loops on cyclic transfer graphs.

What the Interviewer Expects
  • Build a directed adjacency list
  • Use BFS so the first visit gives the minimum hop count
  • Stop expanding nodes at depth k
  • Use a visited map to handle cycles
  • Exclude the flagged account itself from the result
Key Topics to Cover
Breadth-first search
Directed graphs
Cycle handling
Fraud tracing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you weight hops by transfer amount and only follow transfers above a threshold?
  • How would you also follow transfers that must be later in time than the transfer that reached each account?
  • What changes if the graph has hundreds of millions of edges stored in a database?
  • How would you find accounts that sent money into the flagged account?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of (sender, receiver) transfers, a flagged account id and an integer k >= 0.
  • Output: mapping account -> minimum hops for accounts reachable in 1..k hops, sorted by distance then ...
High-Level Design

Build sender -> [receivers]. Run BFS from the flagged account with a dist map that doubles as the visited set. BFS explores in layers, so the first time an account is discovered its distance is mi...


Submit Your Answer
Markdown supported