Samsung Coding Round Questions with Solutions
Last updated 2026-11-19
Reports describe the Samsung R&D coding assessment as DSA-centred, with graph traversal, backtracking, dynamic programming and simulation problems that need a clean implementation rather than a trick. This page gives twelve practice problems in that style, each with a complete runnable solution, its complexity and the common mistake.
They are practice problems for topics the round is commonly reported to cover, not real papers. Pair this page with Samsung interview questions and the how-to on cracking a DSA coding round.
Strategy for long implementation problems
Write the data model first: what is a state, what are the moves, what ends the search. Then choose BFS for minimum moves, DFS or backtracking for counting or constructing, and DP when states repeat. Test on the smallest example by hand before running.
Watch grid bounds and visited marking. Marking a node visited when you push it, not when you pop it, avoids duplicate queue entries in BFS.
Hiring status
For Samsung hiring, the company's own site at research.samsung.com is the place to check. Reports of an SSIR hiring push in October 2025 and a Bengaluru facility opened in February 2024 are quoted on Samsung interview questions with sources; this page adds no further hiring facts.
Samsung Coding Round Questions with Solutions: questions with worked answers
1 Shortest path in a grid maze with BFS.
mediumStart from the source, push neighbours with distance + 1 and stop at the target. Walls are 1 and open cells 0. In the sample the shortest path from the top-left to the bottom-right takes 4 moves. Time O(R x C), space O(R x C). Common mistake: marking visited when popping, which lets cells be queued many times, or forgetting the case where source equals target.
pythonfrom collections import deque def shortest(grid): r, c = len(grid), len(grid[0]) if grid[0][0] or grid[r-1][c-1]: return -1 dist = {(0, 0): 0} q = deque([(0, 0)]) while q: x, y = q.popleft() if (x, y) == (r - 1, c - 1): return dist[(x, y)] for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): nx, ny = x + dx, y + dy if 0 <= nx < r and 0 <= ny < c and not grid[nx][ny] and (nx, ny) not in dist: dist[(nx, ny)] = dist[(x, y)] + 1 q.append((nx, ny)) return -1 print(shortest([[0, 0, 1], [1, 0, 1], [1, 0, 0]])) # 42 Count the islands in a grid of 0s and 1s.
easyScan the grid; when you find an unvisited 1, count one island and flood-fill all connected land cells (four directions) so they are not counted again. For the sample there are 3 islands. Time O(R x C), space O(R x C) for the recursion in the worst case. Common mistake: not marking cells before recursing, which causes infinite recursion, or counting diagonal connections when four-directional is asked.
pythondef islands(g): r, c = len(g), len(g[0]) def dfs(i, j): if 0 <= i < r and 0 <= j < c and g[i][j] == 1: g[i][j] = 2 for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)): dfs(i + di, j + dj) n = 0 for i in range(r): for j in range(c): if g[i][j] == 1: n += 1 dfs(i, j) return n print(islands([[1, 1, 0, 0], [0, 1, 0, 1], [1, 0, 0, 1], [0, 0, 0, 0]])) # 33 Shortest paths from a source with Dijkstra.
mediumPush (0, source) in a min-heap; pop the smallest distance, skip stale entries, and relax each edge. Time O((V + E) log V), space O(V + E). Common mistake: not skipping stale heap entries, which is correct but slower, and using it with negative edges, which is wrong.
pythonimport heapq def dijkstra(n, edges, src): g = [[] for _ in range(n)] for u, v, w in edges: g[u].append((v, w)); g[v].append((u, 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(5, [(0, 1, 4), (0, 2, 1), (2, 1, 2), (1, 3, 1), (2, 3, 5)], 0)) # [0, 3, 1, 4, inf]4 Count the solutions to N-Queens using bitmasks.
hardPlace one queen per row. Three bitmasks track the occupied columns and the two diagonals; free squares are those not in any mask, and the lowest free bit is taken with x & -x. The counts are 4 for N = 6 and 92 for N = 8. Time is exponential, but with pruning it handles N = 12 or so quickly. Common mistake: forgetting to shift the diagonal masks left and right as you go down a row.
c#include <stdio.h> static int solve(int n, int cols, int d1, int d2) { int all = (1 << n) - 1; if (cols == all) return 1; int count = 0; int free_ = all & ~(cols | d1 | d2); while (free_) { int bit = free_ & -free_; free_ -= bit; count += solve(n, cols | bit, ((d1 | bit) << 1) & all, (d2 | bit) >> 1); } return count; } int main(void) { printf("%d %d\n", solve(6, 0, 0, 0), solve(8, 0, 0, 0)); /* 4 92 */ return 0; }5 Split an array into m contiguous parts minimising the largest part sum.
hardBinary search the limit L between max(a) and sum(a). For each L, count the parts a greedy split needs; if it needs at most m, try a smaller L, otherwise a larger one. For [7, 2, 5, 10, 8] with m = 2 the answer is 18, from [7, 2, 5] and [10, 8]. Time O(n log(sum)), space O(1). Common mistake: starting the lower bound at 0 or 1, so a single element can exceed the limit.
pythondef split_array(a, m): lo, hi = max(a), sum(a) def parts(limit): n, cur = 1, 0 for x in a: if cur + x > limit: n += 1; cur = 0 cur += x return n while lo < hi: mid = (lo + hi) // 2 if parts(mid) <= m: hi = mid else: lo = mid + 1 return lo print(split_array([7, 2, 5, 10, 8], 2)) # 186 Count connected components with union-find.
mediumStart with each node as its own set. For each edge, find both roots and union them, counting a merge only when the roots differ. With path compression and union by size, operations are almost O(1), so the whole run is O(n + E alpha(n)). For 6 nodes and edges (0,1), (1,2), (3,4) there are 3 components. Common mistake: counting components by looking at parent[] without calling find, which leaves stale parents.
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 cnt = n for a, b in edges: ra, rb = find(a), find(b) if ra != rb: p[ra] = rb cnt -= 1 return cnt print(components(6, [(0, 1), (1, 2), (3, 4)])) # 37 Topological order: can all courses be finished?
mediumCount in-degrees, put zero in-degree nodes in a queue, and repeatedly remove one and decrement its neighbours. If all nodes are processed the graph is acyclic and the order is valid; otherwise there is a cycle. Time O(V + E), space O(V + E). For 4 courses with prerequisites 0 to 1, 1 to 2, 2 to 3 the order is [0, 1, 2, 3]; adding 3 to 1 creates a cycle. Common mistake: reversing the edge direction.
pythonfrom collections import deque def order(n, edges): g = [[] for _ in range(n)] indeg = [0] * n for a, b in edges: g[a].append(b); indeg[b] += 1 q = deque(i for i in range(n) if indeg[i] == 0) out = [] while q: u = q.popleft(); out.append(u) for v in g[u]: indeg[v] -= 1 if indeg[v] == 0: q.append(v) return out if len(out) == n else None print(order(4, [(0, 1), (1, 2), (2, 3)]), order(4, [(0, 1), (1, 2), (2, 3), (3, 1)])) # [0, 1, 2, 3] None8 0/1 knapsack with a one-dimensional table.
mediumdp[w] is the best value with capacity w. For each item, iterate w from the capacity down to its weight. With weights [1, 3, 4, 5], values [1, 4, 5, 7] and capacity 7, the best value is 9 (weights 3 and 4). Time O(nW), space O(W). Common mistake: iterating upwards, which allows an item to be reused and solves the unbounded version instead.
pythondef knapsack(wt, val, cap): dp = [0] * (cap + 1) for w, v in zip(wt, val): for c in range(cap, w - 1, -1): dp[c] = max(dp[c], dp[c - w] + v) return dp[cap] print(knapsack([1, 3, 4, 5], [1, 4, 5, 7], 7)) # 99 Josephus problem: who survives when every k-th person is removed?
mediumUse the recurrence f(1) = 0 and f(n) = (f(n - 1) + k) mod n for a zero-based position, then add 1. For n = 7 and k = 3 the survivor is person 4. Time O(n), space O(1), compared with O(nk) or O(n^2) for naive simulation with a list. Common mistake: returning the zero-based index when the problem numbers people from 1.
pythondef josephus(n, k): pos = 0 for i in range(2, n + 1): pos = (pos + k) % i return pos + 1 print(josephus(7, 3)) # 410 Longest increasing subsequence in O(n log n).
hardMaintain tails[i], the smallest tail of any increasing subsequence of length i + 1. For each value, binary search the first tail that is not smaller and replace it, or append if none. The length of tails is the answer. For [10, 9, 2, 5, 3, 7, 101, 18] it is 4. Time O(n log n), space O(n). Common mistake: reading tails as the subsequence itself; it is not generally a valid subsequence, only its length is meaningful.
pythonfrom bisect import bisect_left def lis(a): tails = [] for x in a: i = bisect_left(tails, x) if i == len(tails): tails.append(x) else: tails[i] = x return len(tails) print(lis([10, 9, 2, 5, 3, 7, 101, 18])) # 411 Sliding window maximum with a deque.
hardKeep a deque of indices whose values are decreasing. For each new index, drop smaller values from the back, push the index, drop the front if it left the window, and record the front as the maximum once the first window is full. Time O(n) because each index enters and leaves once, space O(k). For [1, 3, -1, -3, 5, 3, 6, 7] and k = 3 the output is [3, 3, 5, 5, 6, 7]. Common mistake: using a heap without removing expired entries.
pythonfrom collections import deque def window_max(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(window_max([1, 3, -1, -3, 5, 3, 6, 7], 3)) # [3, 3, 5, 5, 6, 7]12 Return a matrix in spiral order.
mediumMaintain four boundaries, top, bottom, left and right, and walk the top row, right column, bottom row and left column, shrinking the boundaries after each. Check the bounds again before the bottom and left passes so that a single remaining row or column is not repeated. For [[1,2,3],[4,5,6],[7,8,9]] the order is 1 2 3 6 9 8 7 4 5. Time O(RC), space O(1) beyond the output.
pythondef spiral(m): out = [] t, b, l, r = 0, len(m) - 1, 0, len(m[0]) - 1 while t <= b and l <= r: out += m[t][l:r + 1]; t += 1 for i in range(t, b + 1): out.append(m[i][r]) r -= 1 if t <= b: out += m[b][l:r + 1][::-1]; b -= 1 if l <= r: for i in range(b, t - 1, -1): out.append(m[i][l]) l += 1 return out print(spiral([[1, 2, 3], [4, 5, 6], [7, 8, 9]])) # [1, 2, 3, 6, 9, 8, 7, 4, 5]
Frequently asked questions
Which language should I use for the Samsung coding test?
Use the language the test supports that you know best; C++, Java and Python are the usual choices. Check the platform's allowed languages and time limits in your own invitation.
What difficulty are the problems?
Reports describe a range from medium implementation problems to graph and DP problems. Practise writing them cleanly under time, not just understanding the idea.
Are these actual Samsung problems?
No. They are practice problems in the style of topics the round is commonly reported to cover. Samsung does not publish its papers.
How should I practise simulation problems?
Pick a problem, write out the state and moves, code it, then test on the smallest and the largest inputs. Also read how to crack the Samsung interview.
Sources
Related guides
More in Company Interview Questions
- Samsung R&D Interview Questions and Answers for India Software Roles
- SAP Coding Round Questions with Solutions in Python and Java
- SAP Labs Interview Questions and Answers for Freshers and SDE Roles
- Sasken coding round questions
- Sasken interview questions and answers
- ServiceNow Coding Round Questions With Solutions
- ServiceNow Interview Questions and Answers
- Siemens Coding Round Questions with Solutions
- Siemens Interview Questions and Answers for India Software Roles
- Sopra Steria coding round questions
- Sopra Steria interview questions and answers
- Sprinklr Coding Round Questions With Solutions