FastPrepInvalid Transactions

Invalid Transactions

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Each string in transactions has the form name,time,amount,city.

A transaction is invalid when at least one condition holds:

  • amount > 1000.
  • Another transaction has the same name, occurs within 60 minutes inclusive, and has a different city.

Return every invalid original transaction string in input order. A conflicting pair makes both transactions invalid.

Function

invalidTransactions(transactions: String[]) → String[]

Examples

Example 1

transactions = ["alice,20,800,mtv","alice,50,1200,mtv"]return = ["alice,50,1200,mtv"]

The second amount exceeds 1000. The shared city means the first transaction is not invalidated by the time rule.

Example 2

transactions = ["alice,20,800,mtv","alice,50,100,beijing"]return = ["alice,20,800,mtv","alice,50,100,beijing"]

The two transactions share a name, differ in city, and are 30 minutes apart, so both are invalid.

Example 3

transactions = ["alice,90,100,beijing","bob,100,100,mtv","alice,20,800,mtv"]return = []

Alice's transactions are 70 minutes apart even though they arrive out of time order, and Bob has no same-name comparison.

Constraints

  • 1 <= transactions.length <= 1000.
  • Each row has exactly four comma-separated fields.
  • name and city contain 1 through 20 lowercase English letters.
  • 0 <= time <= 1000.
  • 0 <= amount <= 2000.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] invalidTransactions(String[] transactions) {
    // Write your code here.
}
transactions["alice,20,800,mtv","alice,50,1200,mtv"]
expected["alice,50,1200,mtv"]
Checking account…