FastPrepInvalid Transactions in Time Order

Invalid Transactions in Time Order

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Each string in transactions has the form name,time,amount,city. The array is already sorted by nondecreasing integer time.

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

invalidTransactionsSorted(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,20,800,mtv","alice,90,100,beijing","bob,100,100,mtv"]return = []

Alice's transactions are 70 minutes apart, and Bob has no same-name comparison.

Constraints

  • 1 <= transactions.length <= 100000.
  • Each row has exactly four comma-separated fields.
  • name and city contain 1 through 20 lowercase English letters.
  • 0 <= time <= 10^9, and input times are nondecreasing.
  • 0 <= amount <= 10^9.

More Bloomberg LP problems

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