RRazorpay·DSASDE-2DSA Round
Detect Circular Money Transfers in a Transaction Graph
Problem
Given a list of transactions [sender, receiver, amount], detect all groups of accounts involved in circular money transfers (cycles in the directed graph).
Example
transactions = [[A,B,100],[B,C,50],[C,A,75],[D,E,200]]
Output: [[A,B,C]] -- cycle: A→B→C→A
Constraints
- Up to 10^5 transactions
- Account IDs are strings
What Razorpay looks for
- Graph construction from raw data
- Cycle detection using DFS with coloring (white/grey/black)
- Returning the actual cycle nodes, not just a boolean
Extension
What if you need to detect cycles in near real-time as transactions stream in?
added 6 days ago