KPMG coding round questions
Last updated 2026-11-19
Candidate-shared preparation notes for KPMG's technology roles tend to stress SQL, logical reasoning and basic programming over heavy algorithms. A firm whose work centres on accounts, tax and compliance also has a recognisable data vocabulary: ledgers, balances, account numbers, PAN, tax slabs. The twelve problems below use that vocabulary while testing ordinary skills: grouping, window functions, string validation, arithmetic and a couple of classic puzzles.
They are original practice problems, not a copy of any KPMG test. For the interview rounds, see KPMG interview questions, and use the SQL interview guide for wider query practice.
| Emphasis (commonly reported) | SQL, logic, basic coding |
|---|---|
| Difficulty here | Easy to medium |
| Languages | SQL, Python and Java shown |
Putting SQL first
Five of the twelve problems are queries on a ledger or transaction table. That is deliberate. If a test gives you a database question, it is often the quickest to score on, provided you know the handful of patterns that recur: totals and checks, running balances, latest-row-per-group, and finding the rows that have no partner.
Write the query in small steps. Start with the plain SELECT, add the grouping, then the filter on the groups, then the ordering. Running each step on a three-row table in your head catches most errors before they reach the test.
Format checks and illustrative rules
Several Python and Java problems validate or format values that appear in Indian finance work. The PAN pattern and the tax slabs here are simplified teaching examples. They are not a statement of current law, so never use the sample slabs for a real calculation; consult the tax authority's published rules for that.
Hiring status
No sourced KPMG statement on fresher numbers or dates is held on this site, so none are quoted. Check KPMG India's own careers site for the current process and any test instructions.
KPMG coding round questions: questions with worked answers
1 SQL: confirm that total debits equal total credits in a ledger. Table ledger(id, account, debit, credit).
easySum both columns across the whole table and subtract. A trial balance is in balance when the difference is zero. Showing both totals and the difference lets a reviewer see by how much it is off. Common mistakes: grouping by account, which answers a different question, and forgetting that NULL amounts should be treated as zero with COALESCE.
sqlSELECT SUM(COALESCE(debit, 0)) AS total_debit, SUM(COALESCE(credit, 0)) AS total_credit, SUM(COALESCE(debit, 0)) - SUM(COALESCE(credit, 0)) AS difference FROM ledger;2 SQL: list accounts whose net balance is negative. Table transactions(id, account_id, txn_date, amount) with credits positive and debits negative.
easyGroup by account and sum the signed amounts, then keep groups whose sum is below zero using HAVING. Order by the balance to show the worst first. Common mistakes: filtering negative rows with WHERE, which lists individual debits and not accounts, and using an inner condition on the sign of the latest transaction.
sqlSELECT account_id, SUM(amount) AS balance FROM transactions GROUP BY account_id HAVING SUM(amount) < 0 ORDER BY balance;3 SQL: show each transaction with the running balance of its account, in date order.
mediumUse SUM(amount) as a window function partitioned by account and ordered by date, with the id as a tiebreaker. The running balance restarts for every account. Common mistakes: omitting PARTITION BY, which produces one balance across all accounts, and omitting the tiebreaker so same-day rows swap order between runs.
sqlSELECT account_id, txn_date, amount, SUM(amount) OVER (PARTITION BY account_id ORDER BY txn_date, id) AS balance FROM transactions ORDER BY account_id, txn_date, id;4 SQL: return only the most recent transaction of each account.
mediumNumber each account's transactions from newest to oldest with ROW_NUMBER over a partition, then keep number one in an outer query. The id is the tiebreaker for same-day transactions. Common mistakes: joining to MAX(txn_date) per account, which returns several rows when two share the latest date, and putting the window function inside WHERE.
sqlSELECT account_id, txn_date, amount FROM (SELECT account_id, txn_date, amount, ROW_NUMBER() OVER (PARTITION BY account_id ORDER BY txn_date DESC, id DESC) AS rn FROM transactions) t WHERE rn = 1 ORDER BY account_id;5 SQL: find accounts with no transactions since 1 January 2026. Tables accounts(id, name) and transactions(id, account_id, txn_date, amount).
mediumLeft join accounts to only the recent transactions by putting the date condition in the ON clause, then keep rows where the transaction side is NULL. If the date test moved to WHERE, accounts with no recent rows would be removed before the NULL check and the query would return nothing. Common mistakes: that exact WHERE placement, and an inner join.
sqlSELECT a.id, a.name FROM accounts a LEFT JOIN transactions t ON t.account_id = a.id AND t.txn_date >= '2026-01-01' WHERE t.id IS NULL ORDER BY a.id;6 Validate a PAN-style identifier: five letters, four digits, one letter, with a permitted fourth letter.
easyMatch the whole string against five capital letters, four digits and one capital letter, then check that the fourth character belongs to the allowed category set. The set here (P, C, H, F, A, T, B, L, J, G) follows the commonly described holder-type letters; the pattern is a format check only and does not prove the number exists. O(1). Common mistakes: using a search instead of a full match, and accepting lowercase.
pythonimport re PAN = re.compile(r'[A-Z]{5}[0-9]{4}[A-Z]') def valid_pan(text): return bool(PAN.fullmatch(text)) and text[3] in 'PCHFATBLJG'javaclass Pan { static boolean valid(String s) { return s.matches("[A-Z]{5}[0-9]{4}[A-Z]") && "PCHFATBLJG".indexOf(s.charAt(3)) >= 0; } }7 Mask an account number so only the last four digits show.
easyReplace every character except the last four with a star. If the number is four characters or shorter, mask all of it so nothing real leaks. O(n). Common mistakes: slicing with a negative index on a short string and exposing all of it, and altering the stored value instead of only the displayed copy.
pythondef mask_account(number, keep=4): if len(number) <= keep: return '*' * len(number) return '*' * (len(number) - keep) + number[-keep:]javaclass Mask { static String maskAccount(String number, int keep) { if (number.length() <= keep) return "*".repeat(number.length()); return "*".repeat(number.length() - keep) + number.substring(number.length() - keep); } }8 Format a whole-rupee amount with Indian digit grouping, so 1234567 becomes 12,34,567.
mediumKeep the last three digits together, then group the remaining digits in twos from the right. Handle the sign separately and leave numbers up to three digits alone. O(n) in the number of digits. Common mistakes: using the Western grouping of three, and losing the minus sign when slicing the digits.
pythondef indian_format(n): sign = '-' if n < 0 else '' digits = str(abs(n)) if len(digits) <= 3: return sign + digits head, tail = digits[:-3], digits[-3:] parts = [] while len(head) > 2: parts.insert(0, head[-2:]) head = head[:-2] if head: parts.insert(0, head) return sign + ','.join(parts + [tail])javaclass Inr { static String format(long n) { String sign = n < 0 ? "-" : ""; String s = Long.toString(Math.abs(n)); if (s.length() <= 3) return sign + s; StringBuilder sb = new StringBuilder(s.substring(s.length() - 3)); String head = s.substring(0, s.length() - 3); while (head.length() > 2) { sb.insert(0, head.substring(head.length() - 2) + ","); head = head.substring(0, head.length() - 2); } if (!head.isEmpty()) sb.insert(0, head + ","); return sign + sb; } }9 Compute tax on an income using progressive slabs, where each rate applies only to the part of income inside its band.
mediumWalk the bands in order. For each, tax the portion of income between the band's lower and upper edges at that band's rate, and stop when the income is used up. Use integer arithmetic and divide by 100 once at the end. The slabs in tests are illustrative, so read them from the input, never hard-code them. O(bands). Common mistakes: applying the top rate to the whole income, and dividing by 100 inside the loop so rounding error accumulates.
pythondef slab_tax(income, slabs): total, lower = 0, 0 for upper, rate in slabs: top = income if upper is None else min(income, upper) if top > lower: total += (top - lower) * rate if upper is None or income <= upper: break lower = upper return total // 100javaclass Tax { // each slab is {upperLimit, ratePercent}; upperLimit -1 means no limit static long slabTax(long income, long[][] slabs) { long total = 0, lower = 0; for (long[] s : slabs) { long top = s[0] < 0 ? income : Math.min(income, s[0]); if (top > lower) total += (top - lower) * s[1]; if (s[0] < 0 || income <= s[0]) break; lower = s[0]; } return total / 100; } }10 Puzzle: 100 lockers start closed. Student k toggles every k-th locker, for k = 1 to 100. How many are open at the end?
mediumA locker is toggled once for each of its divisors. It ends open only if it has an odd number of divisors, which happens exactly for perfect squares, since divisors pair up except the square root. So the answer for n lockers is the integer square root of n: 10 for 100. O(1). Common mistakes: simulating with nested loops when a formula exists, and using floating-point square root without correcting rounding.
pythonimport math def open_lockers(n): return math.isqrt(n)javaclass Lockers { static int openLockers(int n) { int r = (int) Math.sqrt(n); while (r * r > n) r--; while ((r + 1) * (r + 1) <= n) r++; return r; } }11 Every ledger entry id appears twice, once as a debit and once as a credit, except one. Find the unpaired id.
mediumXOR all the ids together. A number XORed with itself is zero and XOR is order-independent, so every matched pair cancels and only the unpaired id survives. O(n) time, O(1) space. Common mistakes: using a set or a count map when constant space is asked for, and applying it when ids may appear an odd number of times other than once.
pythonfrom functools import reduce from operator import xor def unpaired(ids): return reduce(xor, ids, 0)javaclass Unpaired { static int unpaired(int[] ids) { int x = 0; for (int id : ids) x ^= id; return x; } }12 Find two ledger entries, one positive and one negative, that cancel each other exactly.
easyScan once, storing each value with its index in a hash map. Before storing a value, look up its negation: if present, the two indices are the answer. O(n) time, O(n) space. Common mistakes: using nested loops, and forgetting that zero cancels with another zero, which the look-up-before-store order handles correctly.
pythondef cancelling_pair(entries): seen = {} for i, value in enumerate(entries): if -value in seen: return seen[-value], i seen[value] = i return Nonejavaimport java.util.*; class Cancel { static int[] cancellingPair(long[] entries) { Map<Long, Integer> seen = new HashMap<>(); for (int i = 0; i < entries.length; i++) { Integer j = seen.get(-entries[i]); if (j != null) return new int[]{j, i}; seen.put(entries[i], i); } return null; } }
Frequently asked questions
What does the KPMG technology test emphasise?
Commonly reported accounts mention SQL, logical reasoning and basic programming. Details differ between roles and years, so confirm them in your own invitation.
Why is there so much SQL on this page?
Database questions are among the most common and the most learnable. Five query patterns here, from totals to anti joins, cover a large share of what an entry-level test can ask.
Are the PAN pattern and tax slabs real rules?
They are simplified teaching examples. Use them to practise string checks and progressive calculation, and consult official publications for real figures.
How do I prepare for the logic puzzles?
Learn to look for structure before simulating. The locker puzzle and the unpaired-entry problem both collapse to one line once you spot the pairing property.
Where can I find the current KPMG process?
On KPMG India's own careers site and in the invitation you receive. Third-party descriptions can lag behind.
Related guides
More in Company Interview Questions
- KPMG interview questions and answers
- L&T Technology Services interview questions
- LatentView Analytics Interview Questions with Answers
- LatentView Coding Round Questions
- LinkedIn Coding Round Questions With Solutions
- LinkedIn Interview Questions and Answers
- Lowe's Coding Round Questions
- Lowe's Interview Questions with Answers
- LTIMindtree Coding Round Questions with Solutions
- LTIMindtree Interview Questions for Freshers
- LTTS coding round questions
- MakeMyTrip Coding Round Questions