r/chalkinterview • u/Uahakan • 6d ago
Library question Bloomberg coding question: Flag suspicious transactions
Mark transactions that are too large, or that come from two places within an hour.
You help a payments team find transactions that may need review when an account appears in different cities too quickly.
You get:
account_names: the account name for each transaction, e.g."lee"amounts: the amount in dollars;amounts[i]belongs toaccount_names[i], e.g.250cities: the city;cities[i]belongs toaccount_names[i], e.g."Oslo"minutes: the timestamp in minutes;minutes[i]belongs toaccount_names[i], e.g.120
All four lists have the same length, and positions start at 0.
Return the suspicious transaction positions in increasing order, with each position listed once:
- A transaction is suspicious if its amount is over
2000; exactly2000is fine. - It is also suspicious if another transaction for the same account is in a different city at most
60minutes before or after it. The limit is inclusive, and transactions in the same city never count. - To check nearby transactions, order them by account name and then minute. Transactions for the same account at the same minute are simultaneous, so each can count the others.
- If the input is empty or no transaction is suspicious, return
[].
For example, with account_names = ["a", "a", "b"], amounts = [100, 2001, 500], cities = ["North", "South", "West"], and minutes = [10, 70, 5]:
- Positions
0and1are in different cities exactly60minutes apart. Position
1is also over2000, so the answer is[0, 1].def suspicious_transactions(account_names: list[str], amounts: list[int], cities: list[str], minutes: list[int]) -> list[int]
Source: reported by a candidate in a public write-up. The wording above is ours.
Practise it out loud with follow-ups: https://chalkinterview.com/questions/bloomberg-flag-suspicious-transactions/?utm_source=reddit&utm_campaign=sub
How would you answer it? Drop your approach below.