Invalid Transactions

MediumArrays & Hashinghashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Each entry of transactions is a comma-separated string "name,time,amount,city", where name and city are lowercase words, time is in minutes, and amount is an integer. A transaction is *possibly invalid* if either: - its amount is strictly greater than 1000, or - some other transaction (a different entry of the list) has the same name, a different city, and a time within 60 minutes of it (difference at most 60, inclusive). Return all possibly invalid transactions, in any order. If the same string appears several times and those entries are invalid, include it once per entry.

Examples

Input: transactions = ["alice,20,800,mtv","alice,50,100,beijing"]
Output: ["alice,20,800,mtv","alice,50,100,beijing"]
Both belong to `alice`, are 30 minutes apart, and happen in different cities, so each is invalid.
Input: transactions = ["alice,20,800,mtv","alice,50,1200,mtv"]
Output: ["alice,50,1200,mtv"]
The two entries share a city, so only the amount rule applies: 1200 > 1000.
Input: transactions = ["alice,20,800,mtv","bob,50,1200,mtv"]
Output: ["bob,50,1200,mtv"]
Different names never interact; `bob` exceeds the amount limit.

Constraints

  • 1 <= transactions.length <= 1000
  • Each name and city has 1 to 10 lowercase letters
  • 0 <= time <= 1000
  • 0 <= amount <= 2000

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems