Invalid Transactions
Real-world version: Flagged Expense ClaimsThe statement here is our own: the same inputs, outputs and technique.
An audit tool receives a day's expense claims as a list of strings. Each entry of transactions has the form "{staff},{minute},{amount},{site}", giving the person who filed it, the minute of the day it was filed, the sum claimed, and the office site it was filed from.
A claim is flagged when either of these holds:
- the amount claimed is more than
1200, or - some other claim in the list carries the same
staffname, was filed from a differentsite, and itsminuteis within60of this claim'sminute(a gap of exactly60counts as within).
Return the flagged claims as the original strings, in any order. Two entries may be byte-for-byte identical; each is judged separately, so each flagged copy appears in the result.
Examples
Example 1
- Input
- transactions = ["dana,120,300,leeds", "dana,180,300,york", "elias,400,1300,leeds"]
- Output
- ["dana,120,300,leeds", "dana,180,300,york", "elias,400,1300,leeds"]
Dana's two claims are 60 minutes apart from different sites, which is within the window, so both are flagged. Elias claims 1300, which is above 1200.
Example 2
- Input
- transactions = ["kai,10,200,perth", "kai,20,200,perth"]
- Output
- []
Both claims come from the same site, so the second rule does not apply, and neither amount is above 1200.
Example 3
- Input
- transactions = ["mira,300,1500,derby", "mira,300,1500,derby"]
- Output
- ["mira,300,1500,derby", "mira,300,1500,derby"]
The two entries are identical and each claims 1500, so each one is flagged on the amount rule and both copies are reported.
Constraints
- 1 <= transactions.length <= 1000
- Each transactions[i] has the form "{staff},{minute},{amount},{site}"
- staff and site consist of lowercase English letters and have length between 1 and 10.
- minute is an integer written in digits, between 0 and 1000.
- amount is an integer written in digits, between 0 and 2000.
- The result may be returned in any order.
The values you return may be in any order.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def invalid_transactions(transactions: list[str]) -> list[str]:public List<String> invalidTransactions(String[] transactions)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Sort the PeopleReal-world version: Season Leaderboard From Two Parallel ListsEasy
- Find Resultant Array After Removing AnagramsReal-world version: Clearing Rearranged Labels Off the ShelfEasy
- Group AnagramsReal-world version: Bin Label FamiliesMedium
- Accounts MergeReal-world version: Merge Crew Badge RecordsMedium