LinkedIn Coding Round Questions With Solutions
Last updated 2026-11-19
LinkedIn coding rounds are commonly reported as LeetCode medium to hard problems, often with a data structure design flavour or a follow-up that raises the constraints. The ten practice problems below follow that style: graphs on connections, nested structures, streaming data and intervals.
They are practice, not real papers. Each gives the approach, code, complexity and the usual mistakes. Pair this with LinkedIn interview questions for the design and behavioural side, and see how to crack a DSA coding round.
How to approach a follow-up
Interviewers often accept your first solution and then change a constraint: the input no longer fits in memory, the stream is unbounded, or the data is sorted. State the complexity of your answer immediately, since it makes the follow-up conversation easier.
Hiring status
We have no sourced LinkedIn hiring dates or numbers, so none are given. Use LinkedIn's own careers site for current openings and the application process. For general preparation see how to crack the online assessment.
LinkedIn Coding Round Questions With Solutions: questions with worked answers
1 Nested list weight sum: each integer is weighted by its depth.
easyRecurse with the current depth, adding value times depth for integers and descending for lists. Time O(n) over all elements, space O(depth). Represent nested input as Python lists. A follow-up reverses the weights; compute the maximum depth first, then weight by maxDepth minus depth plus one.
pythondef depth_sum(nested, depth=1): total = 0 for x in nested: if isinstance(x, list): total += depth_sum(x, depth + 1) else: total += x * depth return total2 Flatten a nested list with an iterator.
mediumKeep a stack of iterators over the nested lists. hasNext advances until the top of the stack yields an integer, popping exhausted iterators and pushing iterators for sublists. Amortised O(1) per element, O(depth) space. Mistake: flattening everything in the constructor, which uses O(n) memory and is wrong for lazy inputs.
pythonclass FlatIter: def __init__(self, nested): self.st = [iter(nested)] self.nxt = None def has_next(self): while self.st and self.nxt is None: try: x = next(self.st[-1]) except StopIteration: self.st.pop() continue if isinstance(x, list): self.st.append(iter(x)) else: self.nxt = x return self.nxt is not None def next(self): if not self.has_next(): raise StopIteration x, self.nxt = self.nxt, None return x3 Word ladder: shortest transformation length.
hardBFS over words, changing one letter at a time and checking membership in a set. Each word has 26 times L neighbours, so the cost is O(N times L squared) with string slicing. Remove words from the set when visited. Bidirectional BFS halves the search depth. Mistake: forgetting that the end word must be in the dictionary.
pythonfrom collections import deque def ladder(begin, end, words): words = set(words) if end not in words: return 0 q, steps = deque([begin]), 1 while q: for _ in range(len(q)): w = q.popleft() if w == end: return steps for i in range(len(w)): for c in 'abcdefghijklmnopqrstuvwxyz': n = w[:i] + c + w[i+1:] if n in words: words.remove(n) q.append(n) steps += 1 return 04 Moving average from a data stream.
easyKeep a queue and a running sum. On each value, add it, and if the queue exceeds the window size, subtract the oldest. Return sum divided by length. O(1) per call, O(window) space. Mistake: recomputing the sum each time, giving O(window) per call; also floating-point drift on very long streams, solved with integer sums.
pythonfrom collections import deque class MovingAverage: def __init__(self, size): self.size, self.q, self.s = size, deque(), 0 def next(self, v): self.q.append(v) self.s += v if len(self.q) > self.size: self.s -= self.q.popleft() return self.s / len(self.q)5 Subarray sum equals K (negative numbers allowed).
mediumKeep a hash map of prefix sum frequencies. For each prefix p, add the count of earlier prefixes equal to p minus k. Start with prefix 0 counted once. Time O(n), space O(n). Mistake: using a sliding window, which only works if all numbers are non-negative.
pythonfrom collections import defaultdict def subarray_sum(a, k): seen = defaultdict(int) seen[0] = 1 p = ans = 0 for x in a: p += x ans += seen[p - k] seen[p] += 1 return ans6 Meeting rooms II: minimum rooms needed.
mediumSort start times and end times separately. Sweep the starts; if the earliest unused end is at or before the start, reuse that room (advance the end pointer), otherwise add a room. Time O(n log n). A min-heap of end times also works.
pythondef min_rooms(intervals): starts = sorted(s for s, _ in intervals) ends = sorted(e for _, e in intervals) rooms = j = 0 for s in starts: if s >= ends[j]: j += 1 else: rooms += 1 return rooms7 Binary tree vertical order traversal.
mediumRun BFS carrying a column index for every node (root 0, left minus one, right plus one), grouping node values by column in a dictionary, then output columns in sorted order. BFS keeps top-to-bottom order within a column. Time O(n log n) for sorting columns, or O(n) by tracking the minimum and maximum column. Mistake: using DFS, which breaks the top-to-bottom order.
pythonfrom collections import deque, defaultdict def vertical(root): if not root: return [] cols = defaultdict(list) q = deque([(root, 0)]) while q: node, c = q.popleft() cols[c].append(node.val) if node.left: q.append((node.left, c - 1)) if node.right: q.append((node.right, c + 1)) return [cols[c] for c in sorted(cols)]8 Shortest distance between two words in a list, called many times.
mediumPreprocess a map from word to sorted index list. For a query, merge the two lists with two pointers and track the minimum difference. Preprocessing O(n), each query O(a + b). Mistake: scanning the whole list on every call.
pythonfrom collections import defaultdict class WordDistance: def __init__(self, words): self.pos = defaultdict(list) for i, w in enumerate(words): self.pos[w].append(i) def shortest(self, a, b): x, y = self.pos[a], self.pos[b] i = j = 0 best = float('inf') while i < len(x) and j < len(y): best = min(best, abs(x[i] - y[j])) if x[i] < y[j]: i += 1 else: j += 1 return best9 Clone a graph of members.
mediumDFS or BFS with a map from original node to its copy. When visiting a neighbour, create its clone if missing, then append it to the current clone neighbours. Time O(V + E). Mistake: not registering the clone before recursing, which loops forever on cycles.
pythonclass N: def __init__(self, val, neighbors=None): self.val, self.neighbors = val, neighbors or [] def clone(node): if not node: return None copy = {node: N(node.val)} st = [node] while st: u = st.pop() for v in u.neighbors: if v not in copy: copy[v] = N(v.val) st.append(v) copy[u].neighbors.append(copy[v]) return copy[node]javastatic Node clone(Node n, java.util.Map<Node,Node> seen) { if (n == null) return null; if (seen.containsKey(n)) return seen.get(n); Node c = new Node(n.val); seen.put(n, c); for (Node v : n.neighbors) c.neighbors.add(clone(v, seen)); return c; }10 Kth largest element in an array.
mediumMaintain a min-heap of size k: push each number and pop when the size exceeds k; the root is the answer. O(n log k) time, O(k) space. Quickselect averages O(n) but is O(n squared) in the worst case unless the pivot is randomised. State both and pick based on whether the array may be modified.
javastatic int kthLargest(int[] a, int k) { java.util.PriorityQueue<Integer> h = new java.util.PriorityQueue<>(); for (int x : a) { h.offer(x); if (h.size() > k) h.poll(); } return h.peek(); }
Frequently asked questions
How hard are LinkedIn coding questions?
Commonly reported as medium with some hard problems, often with follow-ups. Treat that as a pattern, not a fixed rule.
Should I write code in Java or Python?
Either is fine. Pick the language where you are fastest and least error-prone.
Are graph problems common?
The product is a graph, and graph problems are frequently reported, so practise BFS, DFS and topological sort. See graph interview questions.
How many problems per round?
Reports vary between one and two per round. Confirm with your recruiter.
Related guides
More in Company Interview Questions
- LinkedIn Interview Questions and Answers
- Lowe's Coding Round Questions
- Lowe's Interview Questions with Answers
- LTIMindtree Coding Round Questions with Solutions
- LTIMindtree Interview Questions for Freshers
- LTTS coding round questions
- MakeMyTrip Coding Round Questions
- MakeMyTrip Interview Questions with Answers
- Mastercard coding round questions with solutions
- Mastercard interview questions with answers (software engineer)
- Media.net Coding Round Questions With Solutions
- Media.net Interview Questions and Answers