Transactions Flagged by Amount or Cross-City Timing

Quick Overview

Transactions Flagged by Amount or Cross-City Timing. Each transaction string has the form name,time,amount,city.

Transactions Flagged by Amount or Cross-City Timing

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Each transaction string has the form `name,time,amount,city`. Flag a transaction if its amount exceeds 1000 dollars, or if another transaction with the same name but a different city occurs within 60 minutes inclusive. Return all flagged input transaction occurrences in any order, preserving their original string text. ```cpp class Solution { public: vector<string> invalidTransactions(vector<string>& transactions); }; ``` ### Examples **Example 1:** ```text Input: transactions = ["u,10,500,a","u,70,600,b"] Output: ["u,10,500,a","u,70,600,b"] Explanation: The same name appears in different cities exactly60 minutes apart, flagging both. ``` **Example 2:** ```text Input: transactions = ["v,5,1000,a","w,6,1001,a"] Output: ["w,6,1001,a"] Explanation: Only the amount strictly above1000 is flagged; the names differ. ``` ### Constraints - The list has at most 1000 transactions; no positive lower bound is stated. - Each string contains exactly name,time,amount,city in the stated comma-separated format. - Name and city are lowercase words of length 1 to 10. - Time fields are digit strings representing integers in `[0,1000]`. - Amount fields are digit strings representing integers in `[0,2000]`. ### Contract considerations Return each flagged input occurrence once, retaining its original text including any digit formatting. ```hint Read the boundary condition At exactly sixty minutes or exactly one thousand dollars, which comparison boundaries does the stated rule include? ``` ### What a Strong Answer Covers Return each flagged input occurrence once, retaining its original text including any digit formatting. ### Follow-up Questions Optional practice extension, separate from the original task: How could you avoid all-pairs comparisons for a much larger transaction stream?

Overview: Transactions Flagged by Amount or Cross-City Timing. Each transaction string has the form name,time,amount,city.

Bloomberg logo
Bloomberg
Aug 26, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Each transaction string has the form name,time,amount,city. Flag a transaction if its amount exceeds 1000 dollars, or if another transaction with the same name but a different city occurs within 60 minutes inclusive. Return all flagged input transaction occurrences in any order, preserving their original string text.

class Solution {
public:
    vector<string> invalidTransactions(vector<string>& transactions);
};

Examples

Example 1:

Input: transactions = ["u,10,500,a","u,70,600,b"]
Output: ["u,10,500,a","u,70,600,b"]
Explanation: The same name appears in different cities exactly60 minutes apart, flagging both.

Example 2:

Input: transactions = ["v,5,1000,a","w,6,1001,a"]
Output: ["w,6,1001,a"]
Explanation: Only the amount strictly above1000 is flagged; the names differ.

Constraints

  • The list has at most 1000 transactions; no positive lower bound is stated.
  • Each string contains exactly name,time,amount,city in the stated comma-separated format.
  • Name and city are lowercase words of length 1 to 10.
  • Time fields are digit strings representing integers in [0,1000] .
  • Amount fields are digit strings representing integers in [0,2000] .

Contract considerations

Return each flagged input occurrence once, retaining its original text including any digit formatting.

What a Strong Answer Covers Guidance

Return each flagged input occurrence once, retaining its original text including any digit formatting.

Follow-up Questions Guidance

Optional practice extension, separate from the original task: How could you avoid all-pairs comparisons for a much larger transaction stream?