#C4140. Remove Duplicate Transactions
Remove Duplicate Transactions
Remove Duplicate Transactions
You are given a list of financial transactions. Each transaction is represented by three values: an identifier (a string), a timestamp (an integer), and an amount (an integer). Your task is to remove duplicate transactions based on the identifier, keeping only the first occurrence of each identifier in the original order.
The problem can be summarized as follows: Given an integer \( n \) and \( n \) transactions, remove the duplicates such that if a transaction with a given identifier appears more than once, only the first one is retained. The expected time complexity is \( O(n) \) on average.
inputFormat
The input is given via standard input (stdin) in the following format:
- The first line contains an integer \(n\) — the number of transactions.
- The next \(n\) lines each contain three space-separated values: a string identifier, an integer timestamp, and an integer amount.
It is guaranteed that \(0 \leq n \leq 10^5\) and that the identifiers consist of alphanumeric characters.
outputFormat
Output the remaining transactions after removing duplicates. Each transaction should be printed in the order they appear in the input, one per line. The values should be space-separated in the format:
identifier timestamp amount
If no transactions remain, output nothing.
## sample5
txn1 1621400400 150
txn2 1621400500 200
txn1 1621400600 210
txn3 1621400700 300
txn2 1621400800 220
txn1 1621400400 150
txn2 1621400500 200
txn3 1621400700 300
</p>