Paytm Coding Round Questions with Solutions
Last updated 2026-11-19
Paytm moves money between wallets, bank accounts and merchants, so its test material tends to revolve around balances, transaction logs and tables of payments. Candidate write-ups, mostly from earlier years, describe an online test of about an hour with two coding questions plus SQL or multiple-choice items, then technical interviews. That points to short, exact problems where one wrong boundary fails a hidden test.
The eleven exercises here use that payments vocabulary: a capped wallet, cashback thresholds, a card-fraud rule, number validation, bit tricks on transaction ids, a log merge and two SQL queries you can run yourself. They are original practice problems. For the concept side read Paytm interview questions, and for time management see the online assessment guide.
Reading a short test the way a payments team would
With only two coding questions, accuracy beats speed: one clean, fully correct answer outscores two that pass the sample and fail on the edges. Write the one you are more certain of first, then test it on a small input, an empty input and a duplicate-heavy input before touching the second.
Payments data is tabular, so SQL carries real weight. Be comfortable with GROUP BY and HAVING, joins, subqueries and ranking window functions. The last two problems below can be pasted into SQLite as written, which makes them easy to rehearse without installing a database server.
Hiring status
Sourced news is at Paytm hiring; to apply use the careers page on paytm.com. The test shape above is candidate-reported, mostly from earlier years, and may have changed.
Paytm Coding Round Questions with Solutions: questions with worked answers
1 Design a wallet that allows only a limited amount to be loaded each calendar month and refuses overspending.
mediumHold the balance and a map from month to the amount loaded in it. Loading is allowed only if the amount is positive and the month's total after loading stays within the cap; otherwise return false and change nothing. A payment succeeds only when the amount is positive and no more than the balance. Everything is O(1). Store amounts in paise as integers. Typical mistakes are checking the cap against the balance instead of the monthly total, and updating the balance before validating.
pythonclass Wallet: MONTHLY_CAP = 1_000_000 # paise, i.e. Rs 10,000 def __init__(self): self.balance = 0 self.loaded = {} def add_money(self, month, amount): if amount <= 0 or self.loaded.get(month, 0) + amount > self.MONTHLY_CAP: return False self.loaded[month] = self.loaded.get(month, 0) + amount self.balance += amount return True def pay(self, amount): if amount <= 0 or amount > self.balance: return False self.balance -= amount return Truejavaimport java.util.*; class Wallet { private static final long MONTHLY_CAP = 1_000_000L; private long balance = 0; private final Map<String, Long> loaded = new HashMap<>(); synchronized boolean addMoney(String month, long amount) { if (amount <= 0 || loaded.getOrDefault(month, 0L) + amount > MONTHLY_CAP) return false; loaded.merge(month, amount, Long::sum); balance += amount; return true; } synchronized boolean pay(long amount) { if (amount <= 0 || amount > balance) return false; balance -= amount; return true; } synchronized long balance() { return balance; } }2 For several cashback targets, find the first transaction at which cumulative spend reaches each target.
easyBuild the running total once. With non-negative amounts it is non-decreasing, so each target is answered by a binary search for the first prefix that is at least the target; if the search runs off the end, the target is never reached. Preprocessing is O(n) and each query O(log n). Rescanning the list per target is O(n x q). Note that refunds make the prefix non-monotonic and break this approach, so state the non-negative assumption.
pythonimport bisect from itertools import accumulate def first_reaching(spends, targets): pref = list(accumulate(spends)) out = [] for t in targets: i = bisect.bisect_left(pref, t) out.append(i if i < len(pref) else -1) return outjavastatic int[] firstReaching(long[] spends, long[] targets) { int n = spends.length; long[] pref = new long[n]; long run = 0; for (int i = 0; i < n; i++) { run += spends[i]; pref[i] = run; } int[] out = new int[targets.length]; for (int q = 0; q < targets.length; q++) { int lo = 0, hi = n; while (lo < hi) { int mid = (lo + hi) >>> 1; if (pref[mid] >= targets[q]) hi = mid; else lo = mid + 1; } out[q] = lo < n ? lo : -1; } return out; }3 Flag a card used in two different cities within a given number of minutes.
mediumProcess transactions in time order and keep, per card, a queue of recent (time, city) events. Drop events older than the window; if any remaining event has a different city from the current one, flag the transaction; then append the current event. A window is usually short, so scanning it is cheap, and keeping a count of cities per card makes the check O(1). Comparing only against the previous transaction misses an earlier city that is still inside the window.
pythonfrom collections import defaultdict, deque def flag_card_hops(txns, window): # txns: (time, card, city), sorted by time recent, flagged = defaultdict(deque), [] for i, (t, card, city) in enumerate(txns): q = recent[card] while q and t - q[0][0] > window: q.popleft() if any(c != city for _, c in q): flagged.append(i) q.append((t, city)) return flaggedjavaimport java.util.*; static List<Integer> flagCardHops(long[] time, String[] card, String[] city, long window) { Map<String, ArrayDeque<Object[]>> recent = new HashMap<>(); List<Integer> flagged = new ArrayList<>(); for (int i = 0; i < time.length; i++) { ArrayDeque<Object[]> q = recent.computeIfAbsent(card[i], k -> new ArrayDeque<>()); while (!q.isEmpty() && time[i] - (Long) q.peekFirst()[0] > window) q.pollFirst(); for (Object[] e : q) if (!e[1].equals(city[i])) { flagged.add(i); break; } q.addLast(new Object[]{time[i], city[i]}); } return flagged; }4 Normalise an Indian mobile number typed with spaces, dashes or a country prefix.
easyStrip spaces and hyphens, then match one pattern: an optional +91, 91 or 0 prefix followed by ten digits whose first digit is 6 to 9. Return the ten digits, or nothing if the pattern fails. Anchoring with a full match is essential, otherwise a longer digit string containing a valid number passes. Linear in the input length. Forgetting the leading-digit rule accepts numbers beginning 0 to 5 that cannot be mobile numbers.
pythonimport re MOBILE = re.compile(r'(?:\+91|91|0)?([6-9]\d{9})') def normalise_mobile(raw): m = MOBILE.fullmatch(re.sub(r'[\s-]', '', raw)) return m.group(1) if m else Nonejavaimport java.util.regex.*; static final Pattern MOBILE = Pattern.compile("(?:\\+91|91|0)?([6-9]\\d{9})"); static String normaliseMobile(String raw) { Matcher m = MOBILE.matcher(raw.replaceAll("[\\s-]", "")); return m.matches() ? m.group(1) : null; }5 A batch should contain ids 1 to n once each, but one id is duplicated and another is missing. Find both.
easyWalk the batch with a seen set. The id that is already in the set when met again is the duplicate; after the pass, the first value from 1 to n absent from the set is the missing one. O(n) time and space. A constant-space version uses the sum and the sum of squares, but the set is easier to get right under time pressure. Sorting also works at O(n log n). The error to avoid is assuming the duplicate appears exactly next to the original.
pythondef dup_and_missing(batch): n, seen, dup = len(batch), set(), None for x in batch: if x in seen: dup = x seen.add(x) missing = next(i for i in range(1, n + 1) if i not in seen) return dup, missingjavastatic int[] dupAndMissing(int[] batch) { int n = batch.length, dup = -1, missing = -1; boolean[] seen = new boolean[n + 1]; for (int x : batch) { if (seen[x]) dup = x; seen[x] = true; } for (int i = 1; i <= n; i++) if (!seen[i]) { missing = i; break; } return new int[]{dup, missing}; }6 Every transaction id appears twice except two that appear once. Find those two.
mediumXOR all ids: pairs cancel and the result is the XOR of the two unique ids, which is non-zero because they differ. Isolate its lowest set bit; that bit differs between the two answers. Split the ids into those with the bit set and those without, XOR within each group, and each group's XOR is one answer, since duplicates fall in the same group and cancel. O(n) time, O(1) space. Using a hash map works but gives up the constant-space trick the question is after.
pythondef two_singles(ids): x = 0 for v in ids: x ^= v low = x & -x p = q = 0 for v in ids: if v & low: p ^= v else: q ^= v return sorted((p, q))javastatic int[] twoSingles(int[] ids) { int x = 0; for (int v : ids) x ^= v; int low = x & -x, p = 0, q = 0; for (int v : ids) { if ((v & low) != 0) p ^= v; else q ^= v; } return new int[]{Math.min(p, q), Math.max(p, q)}; }7 Merge two time-ordered transaction logs stored as linked lists into one ordered list.
easyCreate a dummy head and a tail pointer. Repeatedly attach the smaller of the two current nodes to the tail and advance that list; when one list ends, attach the rest of the other. Relinking existing nodes uses O(1) extra space and O(m + n) time. Using a less-than-or-equal comparison keeps equal timestamps in their original relative order, so the merge is stable. Forgetting the dummy head forces special handling of the first node.
pythonclass LogNode: def __init__(self, ts, nxt=None): self.ts, self.nxt = ts, nxt def merge_logs(a, b): dummy = tail = LogNode(0) while a and b: if a.ts <= b.ts: tail.nxt, a = a, a.nxt else: tail.nxt, b = b, b.nxt tail = tail.nxt tail.nxt = a or b return dummy.nxtjavaclass LogNode { long ts; LogNode next; LogNode(long ts) { this.ts = ts; } } static LogNode mergeLogs(LogNode a, LogNode b) { LogNode dummy = new LogNode(0), tail = dummy; while (a != null && b != null) { if (a.ts <= b.ts) { tail.next = a; a = a.next; } else { tail.next = b; b = b.next; } tail = tail.next; } tail.next = a != null ? a : b; return dummy.next; }8 Pick day-wise cashback offers to maximise the total when two consecutive days' offers cannot both be claimed.
mediumLet best(i) be the most you can earn from the first i days. Either skip day i and keep best(i-1), or claim it and add best(i-2). Only the last two values are needed, so use two variables. O(n) time, O(1) space. Greedy choices such as always claiming the largest offer fail: with offers 3, 5, 3, taking the middle gives 5 while taking both ends gives 6. Remember the empty and single-day inputs.
pythondef max_cashback(offers): skip = take = 0 for x in offers: skip, take = max(skip, take), skip + x return max(skip, take)javastatic int maxCashback(int[] offers) { int skip = 0, take = 0; for (int x : offers) { int newTake = skip + x; skip = Math.max(skip, take); take = newTake; } return Math.max(skip, take); }9 Find any busy minute in a series of per-minute payment counts, meaning a minute busier than both neighbours.
mediumBinary search on slope. Compare the middle value with its right neighbour: if it is smaller, a peak must lie to the right, so move the left bound up; otherwise a peak lies at or before the middle, so move the right bound down to it. When the bounds meet, that index is a peak. The ends count as peaks if they beat their single neighbour. O(log n). A linear scan is correct but misses the point, and the logic is only valid for adjacent elements that differ.
pythondef find_peak(counts): lo, hi = 0, len(counts) - 1 while lo < hi: mid = (lo + hi) // 2 if counts[mid] < counts[mid + 1]: lo = mid + 1 else: hi = mid return lojavastatic int findPeak(int[] counts) { int lo = 0, hi = counts.length - 1; while (lo < hi) { int mid = (lo + hi) >>> 1; if (counts[mid] < counts[mid + 1]) lo = mid + 1; else hi = mid; } return lo; }10 SQL: show the highest-spending customer in each city, keeping ties.
mediumJoin customers to payments, group by customer to get each total, and rank customers inside each city by that total with RANK partitioned by city. Wrap this in a subquery and keep rank 1. RANK keeps tied customers; ROW_NUMBER would silently drop one. Aggregates inside the window's ORDER BY are legal because grouping happens first. Common errors are ranking before grouping, and grouping by name alone when two customers share a name, so include the id.
sqlSELECT city, name, total FROM ( SELECT c.city, c.name, SUM(p.amount) AS total, RANK() OVER (PARTITION BY c.city ORDER BY SUM(p.amount) DESC) AS rk FROM customers c JOIN payments p ON p.customer_id = c.id GROUP BY c.id, c.city, c.name ) t WHERE rk = 1 ORDER BY city, name;11 SQL: list customers who paid on at least three consecutive days, with the start of the streak.
hardReduce payments to distinct customer-day pairs. Number each customer's days in order; subtracting that row number in days from the date gives the same anchor date for every day in an unbroken run. Group by customer and anchor, keep groups with three or more days, and report the earliest day. The date arithmetic is dialect specific: SQLite uses DATE(day, '-n day'), MySQL uses DATE_SUB, PostgreSQL subtracts an interval. Forgetting DISTINCT lets two payments on one day inflate the streak.
sqlWITH d AS ( SELECT DISTINCT customer_id, DATE(paid_on) AS day FROM payments ), g AS ( SELECT customer_id, day, DATE(day, '-' || ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY day) || ' day') AS anchor FROM d ) SELECT customer_id, MIN(day) AS start_day, COUNT(*) AS days FROM g GROUP BY customer_id, anchor HAVING COUNT(*) >= 3 ORDER BY customer_id, start_day;
Frequently asked questions
How much SQL should I expect in a Paytm-style test?
Candidate reports mention SQL items alongside coding questions. Be fluent in joins, GROUP BY with HAVING, subqueries and ranking window functions, and practise on a real engine such as SQLite.
Why do payment problems stress integers and exact boundaries?
A balance or a threshold that is wrong by one paise or one day changes who gets a payout, so tests probe equality cases deliberately. Decide whether each comparison is strict before coding.
Are the reported formats current?
The accounts are mostly from earlier years, so treat the format as a guide. Confirm what your own invitation says about duration, sections and allowed languages.
Does Autocoder help with SQL questions?
It lists SQL among its supported languages. As with any generated answer, run the query on sample data and check ties and nulls yourself before relying on it.
Sources
Related guides
More in Company Interview Questions
- Paytm Interview Questions and Answers
- Persistent Systems Coding Round Questions with Solutions
- Persistent Systems Interview Questions for Freshers
- PhonePe Coding Round Questions with Solutions
- PhonePe Interview Questions and Answers
- Postman Coding Round Questions With Solutions
- Postman Interview Questions and Answers
- Publicis Sapient Coding Round Questions
- Publicis Sapient Interview Questions with Answers
- PwC coding round questions
- PwC interview questions and answers
- Qualcomm Coding Round Questions with Solutions