Recent Duplicate Transaction Detector
Intuit handles millions of financial transactions daily. Detecting unusual patterns, such as duplicate transaction amounts occurring too frequently, is crucial for fraud detection and maintaining data integrity. This problem simulates a scenario where we need to identify suspicious transactions based on recent duplicates.
You are tasked with implementing a function findSuspiciousTransactions that identifies transactions whose amounts have been seen recently. A transaction is considered "suspicious" if:
amount is not zero.amount is identical to the amount of a previous transaction T_j (where j < i), and the index difference i - j is less than or equal to a given windowSize. If there are multiple previous transactions with the same amount, we only consider the most recent one (i.e., the one with the largest j).Your function should return a list of the ids of all suspicious transactions, in the order they appear in the input.
Input:
transactions: An array of Transaction objects. Each Transaction object has two properties:
id: A string representing a unique transaction identifier.amount: A number representing the transaction amount.windowSize: A number representing the maximum allowed index difference for a duplicate amount to be considered "recent".Output:
strings, where each string is the id of a suspicious transaction.amount of 0 is never considered suspicious, even if duplicated.windowSize will always be a positive integer.transactions array can be empty. If so, return an empty array.ids are unique.Examples
Example 1
Input:
transactions = [{"id": "T1", "amount": 100}, {"id": "T2", "amount": 200}, {"id": "T3", "amount": 100}, {"id": "T4", "amount": 300}, {"id": "T5", "amount": 100}], windowSize = 2
Output:
["T3","T5"]
Note:
T3 (amount 100, index 2) is suspicious because T1 (amount 100, index 0) is within windowSize (2-0 = 2 <= 2). T5 (amount 100, index 4) is suspicious because T3 (amount 100, index 2) is within windowSize (4-2 = 2 <= 2).
Example 2
Input:
transactions = [{"id": "A", "amount": 50}, {"id": "B", "amount": 0}, {"id": "C", "amount": 50}, {"id": "D", "amount": 10}, {"id": "E", "amount": 50}], windowSize = 1
Output:
[]
Note:
B is skipped due to zero amount. For C (amount 50, index 2), the most recent previous 50 was A (index 0). 2-0 = 2, which is > windowSize (1). Not suspicious. For E (amount 50, index 4), the most recent previous 50 was C (index 2). 4-2 = 2, which is > windowSize (1). Not suspicious.
Example 3
Input:
transactions = [{"id": "X", "amount": 10}, {"id": "Y", "amount": 20}, {"id": "Z", "amount": 10}], windowSize = 100
Output:
["Z"]
Note:
Z (amount 10, index 2) is suspicious because X (amount 10, index 0) is within windowSize (2-0 = 2 <= 100).
Constraints
1 <= transactions.length <= 10^51 <= windowSize <= transactions.length-10^9 <= transaction.amount <= 10^9transaction.id will be a non-empty string.ids in the output array must match their order of appearance in the input transactions array.windowSize equal to 1?Loading editor...