r/chalkinterview • • 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 to account_names[i], e.g. 250
  • cities: the city; cities[i] belongs to account_names[i], e.g. "Oslo"
  • minutes: the timestamp in minutes; minutes[i] belongs to account_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; exactly 2000 is fine.
  • It is also suspicious if another transaction for the same account is in a different city at most 60 minutes 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 0 and 1 are in different cities exactly 60 minutes apart.
  • Position 1 is also over 2000, 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.

1 Upvotes

0 comments sorted by