Directi Coding Round Questions With Solutions
Last updated 2026-11-19
Directi algorithm rounds are commonly described as competitive-programming flavoured: you code a full solution, then defend its complexity and handle a harder variant. The eleven problems below are practice in that style, covering greedy choices, dynamic programming, graphs and clean data structure design.
They are practice problems, not real papers. For design and puzzles see Directi interview questions, and for pacing strategy see how to crack a DSA coding round.
How to practise
Solve on a plain editor without autocomplete, since some rounds are reported as written or minimal-tooling. Test with edge cases: empty input, one element, all equal, maximum size. Aim to state complexity before the interviewer asks.
Hiring status
We have no sourced hiring dates, numbers or format details for Directi, so none are stated. Use the company's own careers site for current roles. For general test advice see how to crack the online assessment.
Directi Coding Round Questions With Solutions: questions with worked answers
1 Activity selection: maximum number of non-overlapping intervals.
mediumSort by end time and greedily take every interval that starts at or after the last chosen end. Exchange argument: choosing the earliest finishing interval never reduces what remains. O(n log n). Mistake: sorting by start time or by duration, which fails on simple counterexamples.
pythondef max_activities(iv): iv.sort(key=lambda x: x[1]) end, count = float('-inf'), 0 for s, e in iv: if s >= end: count += 1 end = e return count2 Longest common subsequence.
mediumdp[i][j] is the LCS length of the first i characters of a and the first j of b: dp[i-1][j-1] + 1 on a match, otherwise the maximum of dp[i-1][j] and dp[i][j-1]. O(mn) time, O(min(m, n)) space with rolling rows. To print the sequence, keep the full table and walk back from the corner.
pythondef lcs(a, b): prev = [0] * (len(b) + 1) for x in a: cur = [0] for j, y in enumerate(b, 1): cur.append(prev[j-1] + 1 if x == y else max(prev[j], cur[j-1])) prev = cur return prev[-1]3 Minimum cost to connect all points (minimum spanning tree).
hardUse Kruskal with union-find: sort edges by weight, add an edge if it joins two different components. For n points with all pairwise Manhattan distances, Prim's algorithm in O(n squared) avoids building n squared sorted edges. Mistake: not using path compression, which can degrade union-find.
pythondef mst_cost(points): n = len(points) parent = list(range(n)) def find(x): while parent[x] != x: parent[x] = parent[parent[x]] x = parent[x] return x edges = sorted( (abs(points[i][0]-points[j][0]) + abs(points[i][1]-points[j][1]), i, j) for i in range(n) for j in range(i + 1, n)) total = 0 for w, i, j in edges: a, b = find(i), find(j) if a != b: parent[a] = b total += w return total4 Implement a trie with insert, search and prefix check.
mediumEach node holds a dictionary of children and an end-of-word flag. Insert walks and creates nodes; search requires the end flag; startsWith only requires the path. O(length of word) per operation. A common extension is autocomplete: DFS from the prefix node collecting words.
pythonclass Trie: def __init__(self): self.root = {} def insert(self, w): n = self.root for ch in w: n = n.setdefault(ch, {}) n['$'] = True def _walk(self, p): n = self.root for ch in p: if ch not in n: return None n = n[ch] return n def search(self, w): n = self._walk(w) return bool(n and '$' in n) def starts_with(self, p): return self._walk(p) is not None5 Course schedule II: output a valid order of courses.
mediumRun Kahn's algorithm and record the order of removal. If the order has fewer than n courses, a cycle exists and no valid order does. O(V + E). Mistake: returning a partial order instead of an empty list when a cycle exists.
pythonfrom collections import deque def find_order(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 not indeg[i]) order = [] while q: u = q.popleft() order.append(u) for v in adj[u]: indeg[v] -= 1 if not indeg[v]: q.append(v) return order if len(order) == n else []6 Longest palindromic subsequence.
mediumdp[i][j] is the length for the substring from i to j. If the end characters match, it is 2 plus dp[i+1][j-1]; otherwise the larger of dp[i+1][j] and dp[i][j-1]. Equivalently, the LCS of the string and its reverse. O(n squared). Mistake: confusing it with the longest palindromic substring, which must be contiguous.
pythondef lps(s): n = len(s) dp = [[0] * n for _ in range(n)] for i in range(n - 1, -1, -1): dp[i][i] = 1 for j in range(i + 1, n): if s[i] == s[j]: dp[i][j] = 2 + (dp[i+1][j-1] if i + 1 <= j - 1 else 0) else: dp[i][j] = max(dp[i+1][j], dp[i][j-1]) return dp[0][n-1] if n else 07 Next permutation.
mediumFind the largest i with a[i] less than a[i+1]; if none, reverse the whole array. Otherwise find the largest j with a[j] greater than a[i], swap them, and reverse the suffix after i. O(n) time, O(1) space. Mistake: not reversing the suffix, which leaves it in descending order rather than the smallest arrangement.
pythondef next_permutation(a): i = len(a) - 2 while i >= 0 and a[i] >= a[i + 1]: i -= 1 if i >= 0: j = len(a) - 1 while a[j] <= a[i]: j -= 1 a[i], a[j] = a[j], a[i] a[i + 1:] = reversed(a[i + 1:])javastatic void nextPermutation(int[] a) { int i = a.length - 2; while (i >= 0 && a[i] >= a[i + 1]) i--; if (i >= 0) { int j = a.length - 1; while (a[j] <= a[i]) j--; int t = a[i]; a[i] = a[j]; a[j] = t; } for (int l = i + 1, r = a.length - 1; l < r; l++, r--) { int t = a[l]; a[l] = a[r]; a[r] = t; } }8 Maximum sum of a rectangle no larger than K in a matrix (hard variant of Kadane).
hardFix a pair of rows, collapse the columns into a single array of sums, then find the maximum subarray sum not exceeding K using prefix sums and a sorted structure with binary search. O(rows squared times cols log cols). The plain Kadane variant (no K) drops the log factor. Mistake: forgetting to include the empty prefix of zero.
pythonfrom bisect import bisect_left, insort def max_rect_at_most_k(m, k): R, C = len(m), len(m[0]) best = float('-inf') for top in range(R): col = [0] * C for bottom in range(top, R): for c in range(C): col[c] += m[bottom][c] pre, seen, cur = 0, [0], 0 for x in col: cur += x i = bisect_left(seen, cur - k) if i < len(seen): best = max(best, cur - seen[i]) insort(seen, cur) return best9 Detect and count connected components in an undirected graph.
easyUse union-find or BFS from every unvisited node. Union-find with path compression and union by size runs in nearly linear time and supports adding edges online. Components equal n minus the number of successful unions.
pythondef count_components(n, edges): parent = list(range(n)) def find(x): while parent[x] != x: parent[x] = parent[parent[x]] x = parent[x] return x comps = n for a, b in edges: ra, rb = find(a), find(b) if ra != rb: parent[ra] = rb comps -= 1 return comps10 Design a hit counter that returns hits in the last 5 minutes.
mediumKeep a queue of timestamps; on each hit append, and on a query pop timestamps older than 300 seconds and return the length. For very high traffic, use a circular array of 300 buckets storing a timestamp and count per second, giving O(1) memory regardless of hits. Mistake: storing every hit forever.
pythonfrom collections import deque class HitCounter: def __init__(self): self.q = deque() def hit(self, t): self.q.append(t) def get_hits(self, t): while self.q and self.q[0] <= t - 300: self.q.popleft() return len(self.q)
Frequently asked questions
Is Directi's coding round hard?
Commonly reported as medium to hard and algorithm-focused, with follow-ups on efficiency. The company does not publish difficulty.
Do I need competitive programming experience?
It helps, particularly for greedy, DP and graph problems, but clean reasoning matters more than speed alone.
Which language is best?
Use the language you code fastest in. C++, Java and Python are all common.
Where do I read about the process?
See how to crack the online assessment, and check Directi's own careers site for the live process.
Related guides
More in Company Interview Questions
- Directi Interview Questions and Answers
- Dream11 Coding Round Questions with Solutions
- Dream11 Interview Questions and Answers
- DXC Technology coding round questions
- DXC Technology interview questions and answers
- EPAM Coding Round Questions
- EPAM Interview Questions with Answers
- EY coding round questions
- EY interview questions and answers
- Fidelity Investments coding round questions with solutions
- Fidelity Investments interview questions with answers (engineers)
- Flipkart Coding Round Questions with Solutions