Paytm: Detect Duplicate Transactions
PYTHON coding challenge · Difficulty: easy · Topic: Dictionary and Counter · +50 XP
Problem
A customer taps Pay on Paytm, the network is slow, and the app retries. Sometimes the same payment reaches
the server two or three times. Each copy gets its own txn_id, but it is still the same payment: same
user, same merchant, same amount, same second. Paytm wants a report of these repeated payments so it can
refund the extra copies.
Write find_duplicate_transactions(transactions) that returns every payment which appears more than once,
with the number of times it appears.
Input
transactions is a list of dictionaries. Each dictionary has these keys:
| key | type | example | |---|---|---| | `txn_id` | str | `"TXN1001"` (unique for every record, even for copies) | | `user_id` | str | `"U205"` | | `merchant_id` | str | `"M_IRCTC"` | | `amount` | int | `1200` (whole rupees) | | `timestamp` | str | `"2025-03-01 12:01:10"` |
What counts as a duplicate
Two records are the same payment only when all four of these fields are exactly equal:
user_id, merchant_id, amount and timestamp.
- Ignore
txn_id: copies always have different IDs. - "Exactly equal" means exactly:
"u7"and"U7"are different users, and12:00:05and12:00:06
are different payments.
Output
Return a list of tuples (user_id, merchant_id, amount, timestamp, count):
- one tuple per payment whose
countis 2 or more; countis the total number of records for that payment (the original plus its copies);- tuples in the order each payment first appears in
transactions; - an empty list
[]when nothing is repeated.
Example
| txn_id | user_id | merchant_id | amount | timestamp | |---|---|---|---|---| | TXN1001 | U205 | M_IRCTC | 1200 | 2025-03-01 12:01:10 | | TXN1002 | U101 | M_SWIGGY | 349 | 2025-03-01 12:00:05 | | TXN1003 | U101 | M_SWIGGY | 349 | 2025-03-01 12:00:05 | | TXN1004 | U101 | M_SWIGGY | 349 | 2025-03-01 12:00:06 | | TXN1005 | U205 | M_IRCTC | 1200 | 2025-03-01 12:01:10 | | TXN1006 | U312 | M_ZOMATO | 199 | 2025-03-01 12:02:00 | | TXN1007 | U312 | M_BLINKIT | 199 | 2025-03-01 12:02:00 | | TXN1008 | U205 | M_IRCTC | 1200 | 2025-03-01 12:01:10 |
Output:
`
[('U205', 'M_IRCTC', 1200, '2025-03-01 12:01:10', 3), ('U101', 'M_SWIGGY', 349, '2025-03-01 12:00:05', 2)]
`
U205 / M_IRCTC / 1200 / 12:01:10appears three times (TXN1001, TXN1005, TXN1008), so its count is 3.U101 / M_SWIGGY / 349 / 12:00:05appears twice (TXN1002, TXN1003). TXN1004 is one second later, so it is
a separate payment.
- TXN1006 and TXN1007 have the same user, amount and time but different merchants: not copies.
- U205's payment is listed first because TXN1001 is the first record in the list, even though U101's copy
was spotted earlier.
What you will practise
A dictionary cannot be used as a dictionary key (it is mutable, so it is not hashable). A tuple of
the four fields can: (user_id, merchant_id, amount, timestamp) is a composite key you can count with
a plain dict or collections.Counter. And since Python 3.7 a dict remembers insertion order, which gives
you "order of first appearance" without sorting.
Constraints
0 <= len(transactions) <= 10^5- Aim for one pass over the list: O(n) time.
What this PYTHON challenge teaches you
“Paytm: Detect Duplicate Transactions” is a easy-level PYTHON challenge focused on Dictionary and Counter. Working through it gives you hands-on practice with dictionary, tuple keys, frequency counting, hashing, payments — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.
Concepts covered
- dictionary
- tuple keys
- frequency counting
- hashing
- payments
How to approach it
If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:
- A dict can't be a dictionary key, but a tuple can: build key = (user_id, merchant_id, amount, timestamp) for every record. Leave txn_id out, because every copy has a different one.
- Count each key in a dict: counts[key] = counts.get(key, 0) + 1 (or use collections.Counter).
- Keep only the keys whose count is at least 2, and turn each into (user_id, merchant_id, amount, timestamp, count).
- Don't sort the result. Python dicts keep insertion order, so iterating counts.items() already gives the order in which each payment first appeared.
Interview practice
This problem is good practice for data engineering interviews at companies such as Paytm. Interviewers use problems like it to check whether you can express the logic cleanly and reason about correctness on edge cases such as ties, nulls and empty groups.
How to practise it on PySpark.in
Open the challenge, write your Python code in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.
Related PYTHON challenges
- Most Frequent Element in a List
- GroupBy Aggregation: Sum and Count per Key
- Word Frequency Counter
- Validate Unique User IDs
- Extract Error Codes from Log Strings
- Sum of Values by Key
Helpful resources
Frequently asked questions
Do I need to install Spark or a database to solve this?
No. The PYTHON environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.
Is this challenge free?
Yes - the problem, the sample dataset, the hints and unlimited test runs are free.
What level is it?
It is rated easy and covers Dictionary and Counter.