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.

are different payments.

Output

Return a list of tuples (user_id, merchant_id, amount, timestamp, count):

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)]

`

a separate payment.

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

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

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:

  1. 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.
  2. Count each key in a dict: counts[key] = counts.get(key, 0) + 1 (or use collections.Counter).
  3. Keep only the keys whose count is at least 2, and turn each into (user_id, merchant_id, amount, timestamp, count).
  4. 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

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.

Solve this challenge free on PySpark.in