JJuspay·DSASDE-2Technical Interview – DSA
Detect Circular Money Flows in a Payment Transaction Graph
Problem
Given a list of payment transactions [senderId, receiverId, amount], detect all cycles in the transaction graph — these indicate circular money flows that may signal fraud or settlements.
Example
transactions = [["A","B",100],["B","C",200],["C","A",150],["D","E",50]]
Output: [["A","B","C"]] -- cycle A→B→C→A
Constraints
- Up to 10^5 transactions
- Account IDs are strings (UUIDs in production)
Juspay-specific context
In payment systems, circular flows can represent valid settlement rings (netted clearing) or fraud chains. Your solution should return the full cycle path, not just a boolean.
Expected approach
DFS with three-color marking (unvisited/in-stack/visited). Track the path to reconstruct cycles.
added 6 days ago