Persistent Systems Coding Round Questions with Solutions
Last updated 2026-11-19
This page works through ten medium-to-hard problems that suit product-engineering style tests, with Python and Java solutions, complexity and common mistakes. Persistent has not published its test content, so this is practice for the topics rather than a claimed paper.
Use it with Persistent interview questions and how to crack the DSA coding round.
| Level | Medium to hard |
|---|---|
| Languages | Python and Java shown |
| Topics | Heaps, graphs, union-find, DP, trees |
What these Persistent-style problems cover
Persistent does not publish its test content, so we make no claim about a particular paper. The ten problems here lean on the harder end of what product-engineering firms are commonly said to use: heaps and deques, graph search and shortest paths, union-find, knapsack-style DP and tree traversals. They are practice in the style of those topics. If you are early in preparation, start with an easier set such as Infosys coding round questions and return here.
How to practise these
- Identify the data structure that removes the repeated work (deque, heap, union-find).
- Prove the invariant: what the heap or deque holds at each step.
- Write complexity in terms of the right variables (V, E, k, target).
- Test with a single node, a disconnected graph and ties.
Persistent Systems Coding Round Questions with Solutions: questions with worked answers
1 Sliding window maximum
hardKeep a deque of indices whose values are in decreasing order. Remove indices that left the window from the front, remove smaller values from the back before pushing the new index, and the front is the window maximum. Complexity: O(n) time, O(k) space. Common mistakes: using a heap with lazy deletion carelessly and storing values instead of indices, which makes expiry impossible.
pythonfrom collections import deque def max_window(a, k): dq, out = deque(), [] for i, x in enumerate(a): while dq and a[dq[-1]] <= x: dq.pop() dq.append(i) if dq[0] <= i - k: dq.popleft() if i >= k - 1: out.append(a[dq[0]]) return out print(max_window([1, 3, -1, -3, 5, 3, 6, 7], 3)) # [3, 3, 5, 5, 6, 7]javaimport java.util.*; class Solution { static int[] maxWindow(int[] a, int k) { Deque<Integer> dq = new ArrayDeque<>(); int[] out = new int[a.length - k + 1]; for (int i = 0; i < a.length; i++) { while (!dq.isEmpty() && a[dq.peekLast()] <= a[i]) dq.pollLast(); dq.addLast(i); if (dq.peekFirst() <= i - k) dq.pollFirst(); if (i >= k - 1) out[i - k + 1] = a[dq.peekFirst()]; } return out; } }2 Merge k sorted lists (arrays here)
hardPush the first element of each list into a min-heap with its list and index; pop the smallest, append it, and push that list's next element. The heap holds at most k items. Complexity: O(N log k) time for N total elements, O(k) space. Common mistakes: pushing all N elements at once (O(N log N)) and comparing list objects on ties, which can raise errors in Python without an index tiebreaker.
pythonimport heapq def merge_k(lists): h = [(l[0], i, 0) for i, l in enumerate(lists) if l] heapq.heapify(h); out = [] while h: v, i, j = heapq.heappop(h) out.append(v) if j + 1 < len(lists[i]): heapq.heappush(h, (lists[i][j + 1], i, j + 1)) return out print(merge_k([[1, 4, 5], [1, 3, 4], [2, 6]])) # [1, 1, 2, 3, 4, 4, 5, 6]javaimport java.util.*; class Solution { static List<Integer> mergeK(int[][] lists) { PriorityQueue<int[]> h = new PriorityQueue<>((x, y) -> Integer.compare(x[0], y[0])); for (int i = 0; i < lists.length; i++) if (lists[i].length > 0) h.add(new int[]{lists[i][0], i, 0}); List<Integer> out = new ArrayList<>(); while (!h.isEmpty()) { int[] t = h.poll(); out.add(t[0]); if (t[2] + 1 < lists[t[1]].length) h.add(new int[]{lists[t[1]][t[2] + 1], t[1], t[2] + 1}); } return out; } }3 Shortest path in a binary grid (8 directions)
mediumBreadth-first search from the top-left cell, expanding to eight neighbours, marking visited cells, and counting path length in cells. Return -1 if the start or end is blocked or the end is unreachable. Complexity: O(n squared) time and space for an n by n grid. Common mistakes: using DFS (does not give shortest paths) and marking visited when popping instead of when pushing, which duplicates work.
pythonfrom collections import deque def shortest(g): n = len(g) if g[0][0] or g[-1][-1]: return -1 q, seen = deque([(0, 0, 1)]), {(0, 0)} while q: r, c, d = q.popleft() if (r, c) == (n - 1, n - 1): return d for dr in (-1, 0, 1): for dc in (-1, 0, 1): a, b = r + dr, c + dc if 0 <= a < n and 0 <= b < n and not g[a][b] and (a, b) not in seen: seen.add((a, b)); q.append((a, b, d + 1)) return -1 print(shortest([[0, 0, 0], [1, 1, 0], [1, 1, 0]])) # 4javaimport java.util.*; class Solution { static int shortest(int[][] g) { int n = g.length; if (g[0][0] == 1 || g[n - 1][n - 1] == 1) return -1; boolean[][] seen = new boolean[n][n]; Deque<int[]> q = new ArrayDeque<>(); q.add(new int[]{0, 0, 1}); seen[0][0] = true; while (!q.isEmpty()) { int[] t = q.poll(); if (t[0] == n - 1 && t[1] == n - 1) return t[2]; for (int dr = -1; dr <= 1; dr++) for (int dc = -1; dc <= 1; dc++) { int a = t[0] + dr, b = t[1] + dc; if (a >= 0 && a < n && b >= 0 && b < n && g[a][b] == 0 && !seen[a][b]) { seen[a][b] = true; q.add(new int[]{a, b, t[2] + 1}); } } } return -1; } }4 Dijkstra shortest distances from a source
mediumUse a min-heap of (distance, node). Pop the closest node, skip stale entries, relax each edge, and push improved distances. Works only with non-negative weights. Complexity: O((V + E) log V) time, O(V + E) space. Common mistakes: using it with negative edges (use Bellman-Ford) and not skipping stale heap entries.
pythonimport heapq def dijkstra(n, edges, src): g = [[] for _ in range(n)] for u, v, w in edges: g[u].append((v, w)) dist = [float('inf')] * n; dist[src] = 0 h = [(0, src)] while h: d, u = heapq.heappop(h) if d > dist[u]: continue for v, w in g[u]: if d + w < dist[v]: dist[v] = d + w; heapq.heappush(h, (dist[v], v)) return dist print(dijkstra(4, [(0, 1, 1), (0, 2, 4), (1, 2, 2), (2, 3, 1)], 0)) # [0, 1, 3, 4]javaimport java.util.*; class Solution { static long[] dijkstra(int n, int[][] edges, int src) { List<List<int[]>> g = new ArrayList<>(); for (int i = 0; i < n; i++) g.add(new ArrayList<>()); for (int[] e : edges) g.get(e[0]).add(new int[]{e[1], e[2]}); long[] dist = new long[n]; Arrays.fill(dist, Long.MAX_VALUE); dist[src] = 0; PriorityQueue<long[]> h = new PriorityQueue<>((x, y) -> Long.compare(x[0], y[0])); h.add(new long[]{0, src}); while (!h.isEmpty()) { long[] t = h.poll(); int u = (int) t[1]; if (t[0] > dist[u]) continue; for (int[] e : g.get(u)) if (t[0] + e[1] < dist[e[0]]) { dist[e[0]] = t[0] + e[1]; h.add(new long[]{dist[e[0]], e[0]}); } } return dist; } }5 Number of connected components with union-find
mediumInitialise each node as its own parent. For each edge union the roots with path compression and union by size, decrementing the component count when two different roots merge. Complexity: near O(E * alpha(n)) time, O(n) space. Common mistakes: unioning nodes instead of roots and omitting path compression, which can degrade to O(n) finds.
pythondef components(n, edges): p = list(range(n)) def find(x): while p[x] != x: p[x] = p[p[x]]; x = p[x] return x c = n for a, b in edges: ra, rb = find(a), find(b) if ra != rb: p[ra] = rb; c -= 1 return c print(components(5, [(0, 1), (1, 2), (3, 4)])) # 2javaclass Solution { static int[] p; static int find(int x) { while (p[x] != x) { p[x] = p[p[x]]; x = p[x]; } return x; } static int components(int n, int[][] edges) { p = new int[n]; for (int i = 0; i < n; i++) p[i] = i; int c = n; for (int[] e : edges) { int a = find(e[0]), b = find(e[1]); if (a != b) { p[a] = b; c--; } } return c; } }6 Coin change II: number of combinations
mediumUnbounded knapsack counting combinations: dp[0] = 1, and for each coin in the outer loop update dp[a] += dp[a - coin] for a from coin to amount. Coin order in the outer loop avoids counting permutations. Complexity: O(amount * coins) time, O(amount) space. Common mistakes: swapping the loops, which counts different orderings as different, and using a 2-D table unnecessarily.
pythondef change(amount, coins): dp = [1] + [0] * amount for c in coins: for a in range(c, amount + 1): dp[a] += dp[a - c] return dp[amount] print(change(5, [1, 2, 5])) # 4javaclass Solution { static int change(int amount, int[] coins) { int[] dp = new int[amount + 1]; dp[0] = 1; for (int c : coins) for (int a = c; a <= amount; a++) dp[a] += dp[a - c]; return dp[amount]; } }7 Partition equal subset sum
mediumIf the total is odd the answer is no. Otherwise this is a 0/1 knapsack for target = total / 2: a boolean dp where dp[s] means some subset sums to s, updated from high to low for each number. Complexity: O(n * target) time, O(target) space. Common mistakes: iterating sums upward (reuses an item) and not rejecting odd totals early.
pythondef can_partition(a): t = sum(a) if t % 2: return False t //= 2 dp = [True] + [False] * t for x in a: for s in range(t, x - 1, -1): dp[s] = dp[s] or dp[s - x] return dp[t] print(can_partition([1, 5, 11, 5]), can_partition([1, 2, 3, 5])) # True Falsejavaclass Solution { static boolean canPartition(int[] a) { int t = 0; for (int x : a) t += x; if (t % 2 != 0) return false; t /= 2; boolean[] dp = new boolean[t + 1]; dp[0] = true; for (int x : a) for (int s = t; s >= x; s--) dp[s] = dp[s] || dp[s - x]; return dp[t]; } }8 Kth smallest element in a BST
mediumInorder traversal of a BST visits values in ascending order, so stop at the Kth visited node. An iterative stack lets you stop early without visiting the whole tree. Complexity: O(h + k) time, O(h) space. Common mistakes: doing a full traversal into a list and counting from zero versus one inconsistently.
pythonclass T: def __init__(self, v, l=None, r=None): self.v, self.l, self.r = v, l, r def kth(root, k): st, cur = [], root while cur or st: while cur: st.append(cur); cur = cur.l cur = st.pop(); k -= 1 if k == 0: return cur.v cur = cur.r print(kth(T(3, T(1, None, T(2)), T(4)), 1)) # 1javaimport java.util.*; class Solution { static class T { int v; T l, r; T(int v) { this.v = v; } } static int kth(T root, int k) { Deque<T> st = new ArrayDeque<>(); T cur = root; while (cur != null || !st.isEmpty()) { while (cur != null) { st.push(cur); cur = cur.l; } cur = st.pop(); if (--k == 0) return cur.v; cur = cur.r; } return -1; } }9 Binary tree right side view
mediumLevel-order traversal; the last node of each level is visible from the right. Alternatively use DFS visiting right first and recording the first node at each depth. Complexity: O(n) time, O(w) space. Common mistakes: taking the rightmost child only (misses deeper left nodes when the right subtree is shorter).
pythonfrom collections import deque class T: def __init__(self, v, l=None, r=None): self.v, self.l, self.r = v, l, r def right_view(root): out, q = [], deque([root] if root else []) while q: out.append(q[-1].v) for _ in range(len(q)): n = q.popleft() if n.l: q.append(n.l) if n.r: q.append(n.r) return out print(right_view(T(1, T(2, None, T(5)), T(3, None, T(4))))) # [1, 3, 4]javaimport java.util.*; class Solution { static class T { int v; T l, r; T(int v) { this.v = v; } } static List<Integer> rightView(T root) { List<Integer> out = new ArrayList<>(); if (root == null) return out; Queue<T> q = new LinkedList<>(); q.add(root); while (!q.isEmpty()) { int n = q.size(); for (int i = 0; i < n; i++) { T t = q.poll(); if (i == n - 1) out.add(t.v); if (t.l != null) q.add(t.l); if (t.r != null) q.add(t.r); } } return out; } }10 Minimum meeting rooms
mediumSort meetings by start time. Keep a min-heap of end times for rooms in use; if the earliest ending room is free before the next start, reuse it (pop), then push the new end. The heap size at the end is the answer. Complexity: O(n log n) time, O(n) space. Common mistakes: sorting by end time and comparing with the wrong boundary (a meeting ending at 10 and another starting at 10 can share a room).
pythonimport heapq def min_rooms(iv): iv.sort() h = [] for s, e in iv: if h and h[0] <= s: heapq.heappop(h) heapq.heappush(h, e) return len(h) print(min_rooms([[0, 30], [5, 10], [15, 20]])) # 2javaimport java.util.*; class Solution { static int minRooms(int[][] iv) { Arrays.sort(iv, (a, b) -> Integer.compare(a[0], b[0])); PriorityQueue<Integer> h = new PriorityQueue<>(); for (int[] m : iv) { if (!h.isEmpty() && h.peek() <= m[0]) h.poll(); h.add(m[1]); } return h.size(); } }
Frequently asked questions
How hard is Persistent's coding test?
It is not published. Prep material for product-engineering firms suggests medium problems with some harder ones.
Which topics matter most?
Arrays and strings, hashing, heaps, graphs, DP and trees.
Should I learn Dijkstra?
It is a common medium-to-hard topic, so yes.
Where are real notices?
On Persistent's own careers site.
Related guides
More in Company Interview Questions
- 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
- Qualcomm Interview Questions and Answers for India Software Roles
- Razorpay Coding Round Questions with Solutions