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
Coding & Algorithms
Software Engineer
Tencent
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
Directed graphs
Strongly connected components
Tarjan's algorithm
Iterative DFS
Fraud detection
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported

Related Questions