Detect a Profitable Loop in Ad Credit Exchange Rates
Last updated: November 29, 2026
Quick Overview
Advertisers can convert ad credits between currencies at given directed rates. Determine whether some sequence of conversions starting and ending in the same currency yields more than you started with.
Meta
November 29, 20260
0
0 solved
Advertisers can convert ad credits between currencies at given directed rates. Determine whether some sequence of conversions starting and ending in the same currency yields more than you started with.
Meta's billing systems settle ad spend across many currencies, which makes rate consistency a realistic screen topic. The question checks that you know the log transform that turns products into sums and that you can detect negative cycles with Bellman-Ford. Interviewers also probe floating point handling.
What the Interviewer Expects
- Map a rate product greater than 1 to a negative cycle under -log(rate)
- Use Bellman-Ford with a virtual source to cover disconnected components
- Stop early when a pass makes no change
- Use an epsilon for float comparisons
- Discuss how to extract the actual loop
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 print the arbitrage cycle itself?
- How would you handle rates arriving as a stream?
- Could Floyd-Warshall be used and when is it better?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Up to a few hundred currencies and a few thousand directed rates
(src, dst, r)withr > 0. - Return True if any cycle has rate product greater than 1....
High-Level Design
A cycle with prod(r) > 1 means sum(-log r) < 0, a negative cycle. Bellman-Ford finds those: after n - 1 passes all shortest distances settle unless a negative cycle exists, so one extra pass tha...