Zerodha Coding Round Questions With Solutions
Last updated 2026-11-19
Zerodha's technical assessments are commonly described as practical rather than puzzle-driven: work with market-style data, write small robust utilities, and explain your choices. The ten practice problems below follow that style, built around tick streams, candles, caches and parsing.
They are practice problems, not real papers. For concepts and system questions see Zerodha interview questions, and for general pacing see how to crack a DSA coding round.
How to approach
Read the data format carefully, decide on integer types for prices, and treat malformed or out-of-order input as part of the problem. Prefer simple, readable code with tests for edge cases over clever code.
Hiring status
We have no sourced Zerodha hiring dates, numbers or format details, so none are stated. Use the company's own careers page for current roles. See how to crack the online assessment for general strategy.
Zerodha Coding Round Questions With Solutions: questions with worked answers
1 Build OHLC candles from a stream of ticks.
mediumBucket each tick by timestamp divided by the candle length. For each bucket keep open (first price), high, low and close (last price), and volume. Ticks must be processed in time order, or the open and close must be tracked by timestamp. O(n). Mistake: using the max and min of the whole day for every candle.
pythondef candles(ticks, width): # ticks: (timestamp, price, qty) sorted by timestamp out = {} for t, p, q in ticks: b = t // width * width c = out.get(b) if c is None: out[b] = [p, p, p, p, q] else: c[1] = max(c[1], p) c[2] = min(c[2], p) c[3] = p c[4] += q return [(b, *c) for b, c in sorted(out.items())]2 Merge k sorted tick streams by time.
mediumKeep a min-heap with the next tick from each stream, keyed by timestamp. Pop the smallest, emit it, and push that stream's next tick. O(N log k). Mistake: concatenating and sorting everything, which is O(N log N) and needs all data in memory.
pythonimport heapq def merge_streams(streams): its = [iter(s) for s in streams] h = [] for i, it in enumerate(its): first = next(it, None) if first is not None: heapq.heappush(h, (first[0], i, first)) while h: _, i, tick = heapq.heappop(h) yield tick nxt = next(its[i], None) if nxt is not None: heapq.heappush(h, (nxt[0], i, nxt))3 Cache with time-to-live and a size limit.
mediumCombine an ordered dictionary (for least-recently-used eviction) with an expiry timestamp per key. On get, treat expired entries as missing and delete them. On put, evict from the oldest end when the size limit is exceeded. All operations O(1). Mistake: relying only on lazy expiry, so expired entries that are never read stay forever; sweep periodically.
pythonfrom collections import OrderedDict class TTLCache: def __init__(self, cap, ttl): self.cap, self.ttl, self.d = cap, ttl, OrderedDict() def get(self, k, now): item = self.d.get(k) if item is None: return None v, exp = item if exp <= now: del self.d[k] return None self.d.move_to_end(k) return v def put(self, k, v, now): self.d[k] = (v, now + self.ttl) self.d.move_to_end(k) while len(self.d) > self.cap: self.d.popitem(last=False)4 Simple moving average over the last n prices, plus detecting a crossover.
mediumMaintain a running sum over a fixed window for a short and a long average. A crossover happens when the sign of short minus long changes between consecutive steps. O(1) per tick. Mistake: reporting a crossover while the long window is still filling, before enough data exists.
pythonfrom collections import deque def crossovers(prices, short, long): sw, lw = deque(), deque() ss = ls = 0 prev, out = None, [] for i, p in enumerate(prices): sw.append(p); ss += p lw.append(p); ls += p if len(sw) > short: ss -= sw.popleft() if len(lw) > long: ls -= lw.popleft() if len(lw) == long: diff = ss / short - ls / long if prev is not None and (prev < 0 <= diff or prev > 0 >= diff) and diff != prev: out.append(i) prev = diff return out5 Parse a CSV of trades with quoted fields and commas.
mediumWalk the line character by character with an in-quotes flag: a quote toggles the flag (a doubled quote inside quotes is a literal quote), and a comma outside quotes ends the field. Do not use split on commas. In practice use a library such as the csv module, but the exercise tests careful state handling.
pythondef parse_csv_line(line): fields, cur, inq, i = [], [], False, 0 while i < len(line): ch = line[i] if inq: if ch == '"': if i + 1 < len(line) and line[i + 1] == '"': cur.append('"') i += 1 else: inq = False else: cur.append(ch) elif ch == '"': inq = True elif ch == ',': fields.append(''.join(cur)) cur = [] else: cur.append(ch) i += 1 fields.append(''.join(cur)) return fields6 Fixed-size ring buffer for the last N ticks.
easyUse an array of size N, a write index modulo N and a count. Write overwrites the oldest slot when full. Reading in order starts at the write index when full. All operations O(1) and no allocation after start-up. Mistake: using a list with pop(0), which is O(N).
pythonclass Ring: def __init__(self, n): self.a, self.n, self.w, self.size = [None] * n, n, 0, 0 def push(self, x): self.a[self.w] = x self.w = (self.w + 1) % self.n self.size = min(self.size + 1, self.n) def items(self): start = (self.w - self.size) % self.n return [self.a[(start + i) % self.n] for i in range(self.size)]javaclass Ring { private final long[] a; private int w = 0, size = 0; Ring(int n) { a = new long[n]; } void push(long x) { a[w] = x; w = (w + 1) % a.length; size = Math.min(size + 1, a.length); } }7 Autocomplete for trading symbols.
easyBuild a trie over symbols, storing a list of symbols at each node or running DFS from the prefix node. For a fixed symbol universe, a sorted list with binary search for the prefix range is simpler: find the first symbol at or after the prefix and collect while symbols start with it. O(log n + k).
pythonfrom bisect import bisect_left def autocomplete(sorted_symbols, prefix, limit=10): i = bisect_left(sorted_symbols, prefix) out = [] while i < len(sorted_symbols) and sorted_symbols[i].startswith(prefix) and len(out) < limit: out.append(sorted_symbols[i]) i += 1 return out8 Remove duplicate or out-of-order ticks from a feed using sequence numbers.
easyKeep the last accepted sequence number per symbol. Accept a tick only if its sequence is greater; ignore duplicates and stale ones. If gaps matter, record them for a recovery request. O(1) per tick. Mistake: comparing timestamps instead of sequence numbers, since many ticks can share a timestamp.
pythondef dedupe(ticks): last, out = {}, [] for sym, seq, price in ticks: if seq > last.get(sym, -1): last[sym] = seq out.append((sym, seq, price)) return out9 Find the longest streak of days when the price rose.
easyScan once, extending the current streak when today's price is above yesterday's and resetting to zero otherwise; track the maximum. O(n), O(1) space. Mistake: counting the number of days instead of rises, so be explicit about what a streak of length k means.
pythondef longest_rise(prices): best = cur = 0 for i in range(1, len(prices)): cur = cur + 1 if prices[i] > prices[i - 1] else 0 best = max(best, cur) return best10 Count trades per symbol in a time window using a sliding window.
mediumKeep a deque of (timestamp, symbol) and a dictionary of counts. Add new trades, then evict trades older than the window while decrementing counts, deleting symbols that fall to zero. O(1) amortised. Mistake: forgetting to delete zero counts, so the dictionary grows without bound.
pythonfrom collections import deque, defaultdict class WindowCounter: def __init__(self, window): self.w, self.q, self.c = window, deque(), defaultdict(int) def add(self, t, sym): self.q.append((t, sym)) self.c[sym] += 1 while self.q and self.q[0][0] <= t - self.w: _, s = self.q.popleft() self.c[s] -= 1 if self.c[s] == 0: del self.c[s] return dict(self.c)
Frequently asked questions
Is the Zerodha assessment algorithmic?
Reports describe practical engineering tasks more than puzzle-style problems, but formats vary by role. Prepare both fundamentals and practical code.
Which language should I use?
Use what the role and platform allow; Go and Python are common in the company's public writing, but Java and C++ are fine where allowed.
How should I practise?
Build small tools around market-style data, such as a tick aggregator, and review them for edge cases.
Are there coding tests for freshers?
The company hires in small numbers and processes vary. Check its careers page.
Related guides
More in Company Interview Questions
- Zerodha Interview Questions and Answers
- Zoho Coding Round Questions with Solutions
- Zoho Interview Questions and Answers
- Zomato Coding Round Questions with Solutions
- Zomato Interview Questions and Answers
- ZS Associates Coding and Case Logic Questions
- ZS Associates Interview Questions with Answers
- Accenture Coding Round Questions with Solutions
- Accenture Interview Questions for Freshers
- Adobe Coding Round Questions with Solutions in Python and Java
- Adobe Interview Questions and Answers for SDE Roles
- Amazon Coding Round Questions with Solutions in Python and Java