Detect Circular Transfer Rings in a Payment Ledger
Last updated: November 29, 2026
Quick Overview
Given a list of peer-to-peer transfers (sender, receiver, amount), find every group of two or more accounts where money above a threshold can flow around in a cycle, and rank the groups by total internal flow.
Tencent
November 29, 20260
0
0 solved
Given a list of peer-to-peer transfers (sender, receiver, amount), find every group of two or more accounts where money above a threshold can flow around in a cycle, and rank the groups by total internal flow.
WeChat Pay's risk control teams look for money cycling between accounts, a common signal for wash transfers, cash-out schemes and fraud rings. As a coding question the interviewer wants a candidate to model it as strongly connected components on a directed graph, implement Tarjan or Kosaraju correctly, and survive graphs too deep for recursion.
What the Interviewer Expects
- Models accounts as nodes and qualifying transfers as directed edges
- Identifies strongly connected components as the right notion of a ring
- Implements Tarjan or Kosaraju correctly, ideally iteratively
- Computes internal flow per component and ignores single-node components
- Discusses scale and how this would run on a real transaction graph
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you add a time window so only transfers within 24 hours count?
- How would you run this on billions of edges daily (distributed SCC or label propagation)?
- How would you find the actual cycle path to show an analyst?
- How would you avoid flagging legitimate family groups that pass money back and forth?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: transfers (src, dst, amount) and min_amount. Only transfers with amount >= min_amount are edges. Output: every SCC with at least 2 accounts, as a sorted account list plus the sum of quali...
High-Level Design
A ring exists exactly when accounts are mutually reachable, which is the definition of a strongly connected component. Plan: build an adjacency list, run Tarjan's algorithm to assign every node a comp...