Autocoder

Juspay Coding Round Questions

Last updated 2026-11-19

The reported Juspay hiring challenge has three coding problems in about 90 minutes, which leaves around thirty minutes each including reading and testing. Practice should therefore build speed on graphs, arrays, dynamic programming and a little concurrency. This page works through twelve problems of that style, with solutions in Python, Java and SQL, plus complexity and common mistakes.

These are practice problems in the style of the reported topics, not copies of any test. For the conceptual side, read Juspay interview questions; for time management use the DSA coding round guide.

Coding round (reported)Three problems in about 90 minutes
Languages herePython, Java, SQL
ThemesGraphs, DP, arrays, concurrency, SQL

Strategy for a three-problem, ninety-minute round

Read all three first and start with the one whose pattern you recognise immediately. Write the brute force in a comment, then the optimised version, and run the sample plus two edge cases you invent. Partial scores from passing most test cases beat one perfect solution and two blanks.

Hiring status

The only sourced company facts we hold are the reported format above (MCQ rounds, three coding problems in about 90 minutes, interviews, run on Unstop for the 2025 edition for the 2026 B.Tech batch), from the sources listed below. We hold no 2026-27 dates or openings. See juspay.io/careers for current information.

Juspay Coding Round Questions: questions with worked answers

  1. 1

    Two Sum. Return the indices of the two numbers that add up to a target.

    easy

    Store each value's index in a hash map while scanning; before inserting, check whether target minus the current value is already present. O(n) time, O(n) space. Mistake: using the same element twice because you insert before checking, and returning values instead of indices.

    python
    def two_sum(a, target):
        seen = {}
        for i, x in enumerate(a):
            if target - x in seen:
                return [seen[target - x], i]
            seen[x] = i
        return []
  2. 2

    Valid brackets in a payment expression.

    easy

    Push opening brackets on a stack; on a closing bracket, the top must be its match. At the end the stack must be empty. O(n) time and space. Mistake: forgetting to check for an empty stack before popping, and returning true when openers remain.

    python
    def valid(s):
        pairs = {')': '(', ']': '[', '}': '{'}
        st = []
        for ch in s:
            if ch in '([{':
                st.append(ch)
            elif not st or st.pop() != pairs[ch]:
                return False
        return not st
  3. 3

    Shortest path in a binary matrix from top-left to bottom-right using 8-directional moves, through cells containing 0.

    medium

    BFS from the start, tracking distance by levels, is correct because every move costs one. Return -1 if start or end is blocked. O(rows * cols) time and space. Mistake: marking a cell visited when popping rather than when pushing, which lets the same cell enter the queue many times and can time out.

    python
    from collections import deque
    
    def shortest(g):
        n = len(g)
        if g[0][0] or g[n-1][n-1]:
            return -1
        q = deque([(0, 0, 1)])
        g[0][0] = 1
        while q:
            r, c, d = q.popleft()
            if r == n - 1 and c == n - 1:
                return d
            for dr in (-1, 0, 1):
                for dc in (-1, 0, 1):
                    nr, nc = r + dr, c + dc
                    if 0 <= nr < n and 0 <= nc < n and g[nr][nc] == 0:
                        g[nr][nc] = 1
                        q.append((nr, nc, d + 1))
        return -1
  4. 4

    Network delay time. A signal starts at node k; given directed weighted edges, find the time for all nodes to receive it, or -1.

    medium

    Dijkstra with a min-heap gives shortest times from k; the answer is the maximum distance, or -1 if any node is unreachable. O(E log V). Mistake: using BFS on weighted edges, and forgetting to skip stale heap entries (distance larger than the recorded best).

    python
    import heapq
    
    def network_delay(times, n, k):
        adj = {i: [] for i in range(1, n + 1)}
        for u, v, w in times:
            adj[u].append((v, w))
        dist = {}
        h = [(0, k)]
        while h:
            d, u = heapq.heappop(h)
            if u in dist:
                continue
            dist[u] = d
            for v, w in adj[u]:
                if v not in dist:
                    heapq.heappush(h, (d + w, v))
        return max(dist.values()) if len(dist) == n else -1
  5. 5

    Course schedule: can all tasks be completed given prerequisite pairs?

    medium

    It is cycle detection in a directed graph. Kahn's algorithm: remove zero in-degree nodes repeatedly; if all nodes are removed there is no cycle. O(V + E). Mistake: building the edges in the wrong direction. If a pair (a, b) means b before a, the edge goes b to a, but any consistent direction still detects cycles.

    python
    from collections import deque
    
    def can_finish(n, prereq):
        adj = [[] for _ in range(n)]
        indeg = [0] * n
        for a, b in prereq:
            adj[b].append(a)
            indeg[a] += 1
        q = deque(i for i in range(n) if indeg[i] == 0)
        done = 0
        while q:
            u = q.popleft()
            done += 1
            for v in adj[u]:
                indeg[v] -= 1
                if indeg[v] == 0:
                    q.append(v)
        return done == n
  6. 6

    Count subarrays with sum equal to K.

    medium

    Keep a running prefix sum and a map from prefix value to its count. For each position, add the count of (prefix - K) seen so far. Seed the map with {0: 1}. O(n) time, O(n) space. Mistake: using a sliding window, which only works when all values are non-negative; this problem allows negatives.

    python
    from collections import defaultdict
    
    def subarray_sum(a, k):
        cnt = defaultdict(int)
        cnt[0] = 1
        s = res = 0
        for x in a:
            s += x
            res += cnt[s - k]
            cnt[s] += 1
        return res
  7. 7

    Longest increasing subsequence in O(n log n).

    medium

    Maintain the array tails, where tails[i] is the smallest tail of an increasing subsequence of length i+1. For each number, binary search the first tail that is not smaller (bisect_left) and replace it, or append if none. The length of tails is the answer. O(n log n) time, O(n) space. Mistake: treating tails as the actual subsequence; it only gives the correct length. Use bisect_left for strictly increasing, bisect_right for non-decreasing.

    python
    from bisect import bisect_left
    
    def lis(a):
        tails = []
        for x in a:
            i = bisect_left(tails, x)
            if i == len(tails):
                tails.append(x)
            else:
                tails[i] = x
        return len(tails)
  8. 8

    Coin change: the minimum number of coins to make an amount.

    medium

    Bottom-up DP: dp[a] is the best count for amount a, equal to 1 + min(dp[a - coin]). Start with dp[0] = 0 and infinity elsewhere. O(amount * coins) time, O(amount) space. Mistake: greedy largest-coin-first, which fails for coins {1, 3, 4} and amount 6 (greedy gives 4+1+1, optimal is 3+3).

    python
    def coin_change(coins, amount):
        INF = amount + 1
        dp = [0] + [INF] * amount
        for a in range(1, amount + 1):
            for c in coins:
                if c <= a and dp[a - c] + 1 < dp[a]:
                    dp[a] = dp[a - c] + 1
        return dp[amount] if dp[amount] != INF else -1
  9. 9

    Producer-consumer: implement a bounded buffer in Java where producers block when full and consumers block when empty.

    hard

    The simplest correct answer is ArrayBlockingQueue, whose put and take block. If asked to build it, use a lock and two conditions (notFull, notEmpty), waiting in a while loop and signalling after each change. Throughput is bounded by the lock; a queue per consumer or a lock-free design is the next step. Mistake: using if instead of while around await, which breaks on spurious wakeups, or notifying the wrong condition.

    java
    import java.util.concurrent.*;
    
    public class PC {
        public static void main(String[] args) throws Exception {
            BlockingQueue<Integer> q = new ArrayBlockingQueue<>(5);
            Thread prod = new Thread(() -> {
                try { for (int i = 0; i < 10; i++) q.put(i); q.put(-1); }
                catch (InterruptedException e) { Thread.currentThread().interrupt(); }
            });
            Thread cons = new Thread(() -> {
                try {
                    int x;
                    while ((x = q.take()) != -1) System.out.println("got " + x);
                } catch (InterruptedException e) { Thread.currentThread().interrupt(); }
            });
            prod.start(); cons.start();
            prod.join(); cons.join();
        }
    }
  10. 10

    Sliding-window rate limiter: allow at most N requests per user in any W-second window.

    hard

    Keep a deque of timestamps per user. On a request, drop timestamps older than now minus W, then allow if the deque has fewer than N entries and append the current time. O(1) amortised per request, O(N) memory per user. It is exact, unlike a fixed-window counter that lets a burst of 2N cross a boundary. Mistake: not cleaning old entries, so memory and the count grow forever.

    python
    from collections import deque, defaultdict
    
    class Limiter:
        def __init__(self, n, w):
            self.n, self.w = n, w
            self.log = defaultdict(deque)
    
        def allow(self, user, now):
            q = self.log[user]
            while q and q[0] <= now - self.w:
                q.popleft()
            if len(q) < self.n:
                q.append(now)
                return True
            return False
  11. 11

    SQL: find payments that were retried and succeeded, with the number of failed attempts before success.

    medium

    Assume an attempts table with order_id, attempt_no and status. Count failures per order and join to orders that have a success, using conditional aggregation in one pass. Mistake: counting all attempts including the successful one, or joining the table to itself and duplicating rows.

    sql
    SELECT order_id,
           SUM(CASE WHEN status = 'FAILED'  THEN 1 ELSE 0 END) AS failed_attempts
    FROM payment_attempts
    GROUP BY order_id
    HAVING SUM(CASE WHEN status = 'SUCCESS' THEN 1 ELSE 0 END) > 0
       AND SUM(CASE WHEN status = 'FAILED'  THEN 1 ELSE 0 END) > 0;

Frequently asked questions

How hard are Juspay coding problems?

Reports describe medium problems with graph, array and DP flavour, and the challenge stage is competitive. Practise BFS, Dijkstra, topological sort and basic DP until you can write them without lookup.

Do I need to know concurrency for the coding round?

Concurrency appears in the MCQs and interviews more than in the coding problems, but a producer-consumer or rate limiter implementation is a good thing to have ready.

Which language is best?

Any language the platform supports. Python gives shorter code in a timed round; Java is fine if you know its collections well.

Are these actual Juspay questions?

No, they are practice problems in the style of the reported topics.

Is the test proctored?

We have no sourced proctoring details. Read the rules in your invitation, and see is it safe for what any assistant can and cannot do.

Sources

Related guides

More in Company Interview Questions

See all in this section