Netflix Coding Round Questions with Solutions in Python and Java
Last updated 2026-11-19
Netflix assessments, such as the take-home it describes for new-grad and intern candidates, reward clean, tested code for realistic problems. These ten problems cover rate limiting, time windows, caching, dependency ordering and scheduling.
Write your own solution with tests first, then compare with the worked versions in Python and Java.
| Problems | 10, easy to hard |
|---|---|
| Languages | Python and Java |
| Patterns | Rate limiting, windows, caches, topological order |
| Style | Practical, testable building blocks |
The practical style of Netflix problems
Netflix describes a take-home assessment as the first step for new-grad and intern candidates, which means your code is read as well as run. The problems commonly practised for this style are less about clever tricks and more about small, correct, testable building blocks: rate limiters, caches, counters over time windows, dependency ordering and interval handling. These ten follow that style and are practice problems, not real test content.
For the design and behavioural side see Netflix interview questions.
Mistakes in practical problems
- Using the wall clock directly, which makes the code untestable: inject a clock.
- Ignoring thread safety when the object would be shared.
- Window edge off-by-one errors (is a hit at exactly t minus 300 inside the window?).
- Unbounded memory growth: caches and counters need eviction.
- Writing code with no tests or notes on assumptions.
Hiring status
Netflix says its new-grad hiring is for roles in the United States and that new-grad roles are typically posted in late September or October. Check jobs.netflix.com for current roles, locations and any India openings.
Netflix Coding Round Questions with Solutions in Python and Java: questions with worked answers
1 Logger Rate Limiter: allow a message only if the same message was not printed in the last 10 seconds.
easyKeep a hash map from message to the next time it is allowed. A request at time t is allowed if t is at least the stored value, and then you set the stored value to t + 10. Time O(1), space O(distinct messages), which can be pruned with a periodic cleanup. Mistake: storing the last printed time and comparing with the wrong inequality (exactly 10 seconds later is allowed).
pythonclass Logger: def __init__(self): self.next_ok = {} def should_print(self, t, msg): if t < self.next_ok.get(msg, 0): return False self.next_ok[msg] = t + 10 return Truejavaimport java.util.*; class Logger { private final Map<String, Integer> nextOk = new HashMap<>(); boolean shouldPrint(int t, String msg) { if (t < nextOk.getOrDefault(msg, 0)) return false; nextOk.put(msg, t + 10); return true; } }2 Design Hit Counter: count hits in the past 300 seconds.
mediumKeep a queue of timestamps (timestamps arrive in non-decreasing order). On a query at time t, pop timestamps that are 300 or more seconds old and return the queue length. Hits are O(1), queries amortised O(1), space proportional to hits in the window. For very high traffic, use 300 one-second buckets instead. Mistake: an off-by-one at the window edge: the window is (t - 300, t].
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)javaimport java.util.*; class HitCounter { private final Deque<Integer> q = new ArrayDeque<>(); void hit(int t) { q.add(t); } int getHits(int t) { while (!q.isEmpty() && q.peek() <= t - 300) q.poll(); return q.size(); } }3 Moving Average from a Data Stream with window size k.
easyMaintain a queue of the last k values and a running sum. On each new value add it to the sum, push it, and if the queue is longer than k subtract and pop the oldest. The average is sum divided by the queue size. Time O(1) per value, space O(k). Mistake: recomputing the sum each time, which is O(k), and using integer division.
pythonfrom collections import deque class MovingAverage: def __init__(self, k): self.k, self.q, self.s = k, deque(), 0 def next(self, v): self.q.append(v); self.s += v if len(self.q) > self.k: self.s -= self.q.popleft() return self.s / len(self.q)javaimport java.util.*; class MovingAverage { private final int k; private final Deque<Integer> q = new ArrayDeque<>(); private long s = 0; MovingAverage(int k) { this.k = k; } double next(int v) { q.add(v); s += v; if (q.size() > k) s -= q.poll(); return (double) s / q.size(); } }4 Time-Based Key-Value Store: get the value at the latest timestamp not after t.
mediumPer key, store a list of (timestamp, value) pairs; timestamps for a key are set in increasing order, so the list is sorted. A get does a binary search for the rightmost timestamp at most t. Set is O(1) amortised, get is O(log n). Mistake: using bisect on a list of tuples with a value that may not compare, which is why Python code uses (t, chr(255)) or a separate list of timestamps.
pythonimport bisect class TimeMap: def __init__(self): self.ts, self.vs = {}, {} def set(self, k, v, t): self.ts.setdefault(k, []).append(t) self.vs.setdefault(k, []).append(v) def get(self, k, t): if k not in self.ts: return "" i = bisect.bisect_right(self.ts[k], t) return self.vs[k][i - 1] if i else ""javaimport java.util.*; class TimeMap { private final Map<String, TreeMap<Integer, String>> m = new HashMap<>(); void set(String k, String v, int t) { m.computeIfAbsent(k, x -> new TreeMap<>()).put(t, v); } String get(String k, int t) { TreeMap<Integer, String> tm = m.get(k); if (tm == null) return ""; Map.Entry<Integer, String> e = tm.floorEntry(t); return e == null ? "" : e.getValue(); } }5 Token Bucket rate limiter.
mediumRefill tokens lazily using elapsed time: tokens = min(capacity, tokens + elapsed x rate), then allow the request if at least one token is available and consume it. O(1) time and space per client. Mistake: refilling with a background timer per client, which does not scale, or forgetting thread safety (the Java version is synchronised).
pythonimport time class TokenBucket: def __init__(self, rate, capacity): self.rate, self.cap = rate, capacity self.tokens, self.last = capacity, time.monotonic() def allow(self): now = time.monotonic() self.tokens = min(self.cap, self.tokens + (now - self.last) * self.rate) self.last = now if self.tokens >= 1: self.tokens -= 1 return True return Falsejavaclass TokenBucket { private final double rate; private final long cap; private double tokens; private long last = System.nanoTime(); TokenBucket(double ratePerSec, long capacity) { rate = ratePerSec; cap = capacity; tokens = capacity; } synchronized boolean allow() { long now = System.nanoTime(); tokens = Math.min(cap, tokens + (now - last) / 1e9 * rate); last = now; if (tokens >= 1) { tokens -= 1; return true; } return false; } }6 LRU Cache with per-entry time to live.
hardUse an ordered map from key to (value, expiry). On get, if the entry has expired remove it and return a miss, otherwise move it to the most-recent end. On put, insert, then evict the oldest entry if over capacity. All operations O(1). Pass the clock in as a parameter or function so the code is testable. Mistake: lazily expiring only on get, which leaves dead entries consuming capacity until evicted; evict expired entries from the old end first.
pythonfrom collections import OrderedDict class TTLCache: def __init__(self, cap, ttl, clock): self.cap, self.ttl, self.clock = cap, ttl, clock self.d = OrderedDict() def get(self, k): e = self.d.get(k) if e is None: return None if e[1] <= self.clock(): del self.d[k]; return None self.d.move_to_end(k) return e[0] def put(self, k, v): self.d[k] = (v, self.clock() + self.ttl) self.d.move_to_end(k) if len(self.d) > self.cap: self.d.popitem(last=False)javaimport java.util.*; import java.util.function.LongSupplier; class TTLCache<K, V> { private final int cap; private final long ttl; private final LongSupplier clock; private final LinkedHashMap<K, Object[]> d = new LinkedHashMap<>(16, 0.75f, true); TTLCache(int cap, long ttl, LongSupplier clock) { this.cap = cap; this.ttl = ttl; this.clock = clock; } @SuppressWarnings("unchecked") V get(K k) { Object[] e = d.get(k); if (e == null) return null; if ((long) e[1] <= clock.getAsLong()) { d.remove(k); return null; } return (V) e[0]; } void put(K k, V v) { d.put(k, new Object[]{v, clock.getAsLong() + ttl}); if (d.size() > cap) d.remove(d.keySet().iterator().next()); } }7 Build Order: order tasks given dependencies, or detect a cycle.
mediumTopological sort with Kahn's algorithm: compute in-degrees, process nodes with zero in-degree and reduce their neighbours. If the output has fewer nodes than the total, there is a cycle and no valid order. Time O(V + E). This is the shape of build-system or deployment-ordering questions. Mistake: returning a partial order when a cycle exists.
pythonfrom collections import deque def build_order(n, deps): adj = [[] for _ in range(n)]; deg = [0] * n for a, b in deps: # a must come before b adj[a].append(b); deg[b] += 1 q = deque(i for i in range(n) if deg[i] == 0); order = [] while q: u = q.popleft(); order.append(u) for v in adj[u]: deg[v] -= 1 if deg[v] == 0: q.append(v) return order if len(order) == n else []javaimport java.util.*; class Solution { List<Integer> buildOrder(int n, int[][] deps) { List<List<Integer>> adj = new ArrayList<>(); for (int i = 0; i < n; i++) adj.add(new ArrayList<>()); int[] deg = new int[n]; for (int[] d : deps) { adj.get(d[0]).add(d[1]); deg[d[1]]++; } Deque<Integer> q = new ArrayDeque<>(); for (int i = 0; i < n; i++) if (deg[i] == 0) q.add(i); List<Integer> order = new ArrayList<>(); while (!q.isEmpty()) { int u = q.poll(); order.add(u); for (int v : adj.get(u)) if (--deg[v] == 0) q.add(v); } return order.size() == n ? order : new ArrayList<>(); } }8 Task Scheduler: minimum time to run tasks when the same task needs n idle slots between runs.
mediumLet m be the highest task frequency and c the number of tasks with that frequency. The frame needs (m - 1) x (n + 1) + c slots; if there are more tasks than that, no idle time is needed and the answer is the number of tasks. So the answer is max(len(tasks), (m - 1) x (n + 1) + c). Time O(len), space O(26). Mistake: simulating with a heap when a formula suffices, or forgetting the tie term c.
pythonfrom collections import Counter def least_interval(tasks, n): cnt = Counter(tasks) m = max(cnt.values()) c = sum(1 for v in cnt.values() if v == m) return max(len(tasks), (m - 1) * (n + 1) + c)javaclass Solution { int leastInterval(char[] tasks, int n) { int[] cnt = new int[26]; for (char t : tasks) cnt[t - 'A']++; int m = 0, c = 0; for (int v : cnt) { if (v > m) { m = v; c = 1; } else if (v == m) c++; } return Math.max(tasks.length, (m - 1) * (n + 1) + c); } }9 Top K Frequent Words, ties broken alphabetically.
mediumCount words, then sort by (negative frequency, word), or keep a heap of size k with a comparator that treats lower frequency and then larger word as worse. Sorting is O(n log n); the heap is O(n log k). Mistake: ignoring the tie-break order or sorting words by frequency only.
pythonfrom collections import Counter import heapq def top_k_words(words, k): cnt = Counter(words) return heapq.nsmallest(k, cnt, key=lambda w: (-cnt[w], w))javaimport java.util.*; class Solution { List<String> topK(String[] words, int k) { Map<String, Integer> cnt = new HashMap<>(); for (String w : words) cnt.merge(w, 1, Integer::sum); List<String> ws = new ArrayList<>(cnt.keySet()); ws.sort((a, b) -> cnt.get(a).equals(cnt.get(b)) ? a.compareTo(b) : cnt.get(b) - cnt.get(a)); return ws.subList(0, k); } }10 Insert Interval: add a new interval to a sorted list of non-overlapping intervals (for example viewing sessions) and merge.
mediumThree phases in one pass: copy intervals that end before the new one starts, merge all that overlap by taking min start and max end, then copy the rest. Time O(n), space O(n). Mistake: sorting everything again (O(n log n)) when the input is already sorted, and using strict inequality so touching intervals are not merged.
pythondef insert(iv, new): out, i, n = [], 0, len(iv) while i < n and iv[i][1] < new[0]: out.append(iv[i]); i += 1 while i < n and iv[i][0] <= new[1]: new = [min(new[0], iv[i][0]), max(new[1], iv[i][1])]; i += 1 out.append(new) out.extend(iv[i:]) return outjavaimport java.util.*; class Solution { int[][] insert(int[][] iv, int[] nw) { List<int[]> out = new ArrayList<>(); int i = 0, n = iv.length; while (i < n && iv[i][1] < nw[0]) out.add(iv[i++]); while (i < n && iv[i][0] <= nw[1]) { nw = new int[]{Math.min(nw[0], iv[i][0]), Math.max(nw[1], iv[i][1])}; i++; } out.add(nw); while (i < n) out.add(iv[i++]); return out.toArray(new int[0][]); } }
Frequently asked questions
Is the Netflix coding round LeetCode style?
Netflix describes a take-home assessment for new grads and interns. Practical problems such as rate limiters and caches are good preparation; puzzle-style problems are less central.
Which language should I use for Netflix problems?
Use the language you write cleanest tested code in. Python and Java both work for all ten problems here.
Should I add tests to my solutions?
Yes. For a take-home, tests and a short README of assumptions show how you work.
Where can I check Netflix openings?
On Netflix's careers site, jobs.netflix.com.
Sources
Related guides
- Netflix Interview Questions and Answers for Engineers
- Uber Coding Round Questions with Solutions in Python and Java
- Atlassian Coding Round Questions with Solutions in Python and Java
- Google Coding Round Questions with Solutions in Python and Java
- Amazon Coding Round Questions with Solutions in Python and Java
- System Design Interview Questions with Worked Designs
More in Company Interview Questions
- Netflix Interview Questions and Answers for Engineers
- NTT DATA coding round questions
- NTT DATA interview questions and answers
- Nutanix Coding Round Questions With Solutions
- Nutanix Interview Questions and Answers
- NVIDIA Coding Round Questions with Solutions
- NVIDIA Interview Questions and Answers for India Software Roles
- NXP Coding Round Questions with Solutions
- NXP Interview Questions and Answers for India Embedded Software Roles
- Nykaa Coding Round Questions with Solutions
- Nykaa Interview Questions and Answers
- Ola Coding Round Questions with Solutions