Nykaa Coding Round Questions with Solutions
Last updated 2026-11-19
Nykaa sells beauty and personal-care products, and that business has quirks a generic problem set never touches: shades that must be matched by colour, items that expire, ingredients that should not be used together, gift kits built to a budget and launches that draw a crowd all at once. The company does not publish how it tests candidates and this site has no sourced account of its rounds, so this page is a practice set, not a prediction.
Each of the ten problems takes one of those retail quirks and maps it onto a standard technique, with Python and Java code, cost and the slip to avoid. Use them alongside Nykaa interview questions for design and HR preparation, and how to crack the DSA coding round for approach.
Turning a retail story into a known pattern
Every problem here has a plain-English version first. Practise stripping the story: shade matching is nearest neighbour, ingredient conflicts are two-colouring, expiry-aware dispatch is a priority queue, a launch waitlist is a queue built from stacks. Naming the pattern in the first minute is half of solving it.
Then check the constraints. A few hundred shades allow a linear scan, a million products do not. Saying that aloud shows you choose an algorithm from the input size and not from habit.
Hiring status
There is no sourced Nykaa hiring statement on this site and no page for it under /hiring. Look at the careers section of the company's own website for current roles and what the selection steps really are.
Nykaa Coding Round Questions with Solutions: questions with worked answers
1 Pick the foundation shade closest to a customer's skin tone given as RGB values.
easyCompare squared distance in RGB space between the target and every shade, keeping the minimum; squaring avoids a square root and does not change which shade is nearest. One pass, O(shades). For a very large palette queried many times, a k-d tree cuts the search cost. The mistake is comparing channels one at a time, or using absolute differences summed unevenly, which can prefer a shade that is far off in one channel.
pythondef nearest_shade(palette, target): # palette: [(name, (r, g, b)), ...] def dist(item): return sum((a - b) ** 2 for a, b in zip(item[1], target)) return min(palette, key=dist)[0]javastatic String nearestShade(String[] names, int[][] rgb, int[] target) { String best = null; long bestD = Long.MAX_VALUE; for (int i = 0; i < names.length; i++) { long d = 0; for (int c = 0; c < 3; c++) { long diff = rgb[i][c] - target[c]; d += diff * diff; } if (d < bestD) { bestD = d; best = names[i]; } } return best; }2 Split products into a morning and an evening routine so that no conflicting pair lands in the same routine.
mediumDraw an edge between every conflicting pair; the question is whether the graph is bipartite. Colour a start node, then breadth-first search, giving each neighbour the opposite colour. If a neighbour already has the same colour as the current node, a split is impossible, as in any odd cycle such as three mutually conflicting products. Cover every connected component by starting a search from each uncoloured node. O(V + E). Starting from only one node misses disconnected products.
pythonfrom collections import deque def split_routines(n, conflicts): adj = [[] for _ in range(n)] for a, b in conflicts: adj[a].append(b) adj[b].append(a) colour = [-1] * n for s in range(n): if colour[s] != -1: continue colour[s] = 0 q = deque([s]) while q: u = q.popleft() for v in adj[u]: if colour[v] == -1: colour[v] = 1 - colour[u] q.append(v) elif colour[v] == colour[u]: return None return colourjavaimport java.util.*; static int[] splitRoutines(int n, int[][] conflicts) { List<List<Integer>> adj = new ArrayList<>(); for (int i = 0; i < n; i++) adj.add(new ArrayList<>()); for (int[] e : conflicts) { adj.get(e[0]).add(e[1]); adj.get(e[1]).add(e[0]); } int[] colour = new int[n]; Arrays.fill(colour, -1); for (int s = 0; s < n; s++) { if (colour[s] != -1) continue; colour[s] = 0; ArrayDeque<Integer> q = new ArrayDeque<>(); q.add(s); while (!q.isEmpty()) { int u = q.poll(); for (int v : adj.get(u)) { if (colour[v] == -1) { colour[v] = 1 - colour[u]; q.add(v); } else if (colour[v] == colour[u]) return null; } } } return colour; }3 Ship stock first-expiring-first and refuse an order the warehouse cannot fully cover.
mediumHold batches in a min-heap keyed by expiry date. Before serving a request, discard batches already past their date from the top, then check that the remaining quantity covers the request; if not, return nothing and change nothing. Otherwise take from the earliest batch, spilling into the next, and mutate the top entry's quantity in place, which is safe because the heap key does not change. O(log b) per batch touched. Serving expired stock, or partly filling an order before discovering a shortfall, are the failures to avoid.
pythonimport heapq class Stock: def __init__(self): self.heap = [] # [expiry_day, batch_id, qty] def add(self, batch_id, expiry, qty): heapq.heappush(self.heap, [expiry, batch_id, qty]) def take(self, qty, today): while self.heap and self.heap[0][0] < today: heapq.heappop(self.heap) # expired, write off if sum(b[2] for b in self.heap) < qty: return None used = [] while qty: batch = self.heap[0] n = min(qty, batch[2]) used.append((batch[1], n)) qty -= n if n == batch[2]: heapq.heappop(self.heap) else: batch[2] -= n return usedjavaimport java.util.*; class Stock { private final PriorityQueue<int[]> heap = new PriorityQueue<>((a, b) -> a[0] != b[0] ? a[0] - b[0] : a[1] - b[1]); void add(int batchId, int expiry, int qty) { heap.add(new int[]{expiry, batchId, qty}); } List<int[]> take(int qty, int today) { while (!heap.isEmpty() && heap.peek()[0] < today) heap.poll(); int have = 0; for (int[] b : heap) have += b[2]; if (have < qty) return null; List<int[]> used = new ArrayList<>(); while (qty > 0) { int[] batch = heap.peek(); int n = Math.min(qty, batch[2]); used.add(new int[]{batch[1], n}); qty -= n; if (n == batch[2]) heap.poll(); else batch[2] -= n; } return used; } }4 Find the longest ingredient sequence two products share, in the same order.
mediumLet dp[i][j] be the length of the longest common subsequence of the first i items of one list and the first j of the other. A match extends the diagonal; otherwise take the better of dropping an item from either list. Walk back from the bottom-right corner to rebuild the sequence itself. O(m x n) time and space. Mixing up a subsequence, which may skip items, with a substring, which may not, gives the wrong recurrence.
pythondef common_ingredients(a, b): m, n = len(a), len(b) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(m): for j in range(n): dp[i + 1][j + 1] = dp[i][j] + 1 if a[i] == b[j] else max(dp[i][j + 1], dp[i + 1][j]) out, i, j = [], m, n while i and j: if a[i - 1] == b[j - 1]: out.append(a[i - 1]) i, j = i - 1, j - 1 elif dp[i - 1][j] >= dp[i][j - 1]: i -= 1 else: j -= 1 return out[::-1]javaimport java.util.*; static List<String> commonIngredients(String[] a, String[] b) { int m = a.length, n = b.length; int[][] dp = new int[m + 1][n + 1]; for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) dp[i + 1][j + 1] = a[i].equals(b[j]) ? dp[i][j] + 1 : Math.max(dp[i][j + 1], dp[i + 1][j]); LinkedList<String> out = new LinkedList<>(); int i = m, j = n; while (i > 0 && j > 0) { if (a[i - 1].equals(b[j - 1])) { out.addFirst(a[i - 1]); i--; j--; } else if (dp[i - 1][j] >= dp[i][j - 1]) i--; else j--; } return out; }5 List every gift kit whose item prices add up exactly to a budget, using each product at most once.
mediumSort the prices and backtrack with a start index so each product is considered once and combinations are not repeated in a different order. Skip a price equal to the previous one at the same depth to avoid duplicate kits, and stop the loop as soon as a price exceeds what remains, which sorting makes safe. Worst case exponential, but pruning keeps typical inputs fast. Forgetting the duplicate skip yields repeated kits, and forgetting to advance the start index reuses one product.
pythondef kits(prices, target): prices = sorted(prices) result, cur = [], [] def go(start, remaining): if remaining == 0: result.append(list(cur)) return for i in range(start, len(prices)): if i > start and prices[i] == prices[i - 1]: continue if prices[i] > remaining: break cur.append(prices[i]) go(i + 1, remaining - prices[i]) cur.pop() go(0, target) return resultjavaimport java.util.*; static List<List<Integer>> kits(int[] prices, int target) { int[] p = prices.clone(); Arrays.sort(p); List<List<Integer>> result = new ArrayList<>(); go(p, 0, target, new ArrayList<>(), result); return result; } private static void go(int[] p, int start, int remaining, List<Integer> cur, List<List<Integer>> out) { if (remaining == 0) { out.add(new ArrayList<>(cur)); return; } for (int i = start; i < p.length; i++) { if (i > start && p[i] == p[i - 1]) continue; if (p[i] > remaining) break; cur.add(p[i]); go(p, i + 1, remaining - p[i], cur, out); cur.remove(cur.size() - 1); } }6 Build a launch-day waitlist queue out of two stacks.
easyUse an inbox stack for new arrivals and an outbox stack for departures. A pop or peek reads from the outbox; when it is empty, move every item from the inbox across, which reverses their order so the oldest ends on top. Each item is moved at most once, so every operation is O(1) amortised. Moving items on every pop makes it O(n) per call, and moving while the outbox still has items breaks first-in-first-out order.
pythonclass Waitlist: def __init__(self): self.inbox, self.outbox = [], [] def join(self, x): self.inbox.append(x) def _fill(self): if not self.outbox: while self.inbox: self.outbox.append(self.inbox.pop()) def serve(self): self._fill() return self.outbox.pop() if self.outbox else None def next_up(self): self._fill() return self.outbox[-1] if self.outbox else Nonejavaimport java.util.*; class Waitlist { private final ArrayDeque<Integer> inbox = new ArrayDeque<>(), outbox = new ArrayDeque<>(); void join(int x) { inbox.push(x); } private void fill() { if (outbox.isEmpty()) while (!inbox.isEmpty()) outbox.push(inbox.pop()); } Integer serve() { fill(); return outbox.isEmpty() ? null : outbox.pop(); } Integer nextUp() { fill(); return outbox.isEmpty() ? null : outbox.peek(); } }7 Count the ways to pick one offer from each of four lists so the discounts sum to zero.
mediumSplit the four lists into two pairs. Store every sum of one offer from the first list and one from the second in a hash map with its frequency. Then for every sum of one offer from the third and one from the fourth, add the map's count for its negation. This reduces O(n to the fourth) to O(n squared) time and O(n squared) space. Counting distinct values rather than index choices undercounts when offers repeat, which is why frequencies matter.
pythonfrom collections import Counter def zero_sum_picks(a, b, c, d): left = Counter(x + y for x in a for y in b) return sum(left[-(x + y)] for x in c for y in d)javaimport java.util.*; static int zeroSumPicks(int[] a, int[] b, int[] c, int[] d) { Map<Integer, Integer> left = new HashMap<>(); for (int x : a) for (int y : b) left.merge(x + y, 1, Integer::sum); int total = 0; for (int x : c) for (int y : d) total += left.getOrDefault(-(x + y), 0); return total; }8 Are two product names exactly one edit apart, where an edit is an insert, delete or replace of one character?
mediumIf the lengths differ by more than one, answer no. Otherwise make the first string the shorter one and scan for the first mismatch. With equal lengths the rest must match after skipping one character in both; with different lengths it must match after skipping one character of the longer. If no mismatch occurs, the strings are one edit apart only when their lengths differ by one. O(n). Identical strings are zero edits away, so return false for them, a case people overlook.
pythondef one_edit(s, t): if abs(len(s) - len(t)) > 1: return False if len(s) > len(t): s, t = t, s for i in range(len(s)): if s[i] != t[i]: if len(s) == len(t): return s[i + 1:] == t[i + 1:] return s[i:] == t[i + 1:] return len(t) - len(s) == 1javastatic boolean oneEdit(String s, String t) { if (Math.abs(s.length() - t.length()) > 1) return false; if (s.length() > t.length()) { String x = s; s = t; t = x; } for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != t.charAt(i)) { if (s.length() == t.length()) return s.substring(i + 1).equals(t.substring(i + 1)); return s.substring(i).equals(t.substring(i + 1)); } } return t.length() - s.length() == 1; }9 Show how many orders arrived in the last five minutes, even at launch-day volume.
mediumKeep a queue of (second, count) buckets plus a running total. Recording an order either bumps the newest bucket or appends one; counting first evicts buckets older than the window from the front and subtracts them from the total. Memory is bounded by the window length in seconds instead of by the number of orders, and each operation is amortised O(1). Storing one entry per order is the simple version that fails under heavy load.
pythonfrom collections import deque class OrderCounter: def __init__(self, window=300): self.window, self.buckets, self.total = window, deque(), 0 def record(self, ts): if self.buckets and self.buckets[-1][0] == ts: self.buckets[-1][1] += 1 else: self.buckets.append([ts, 1]) self.total += 1 def count(self, now): while self.buckets and self.buckets[0][0] <= now - self.window: self.total -= self.buckets.popleft()[1] return self.totaljavaimport java.util.*; class OrderCounter { private final long window; private final ArrayDeque<long[]> buckets = new ArrayDeque<>(); private long total = 0; OrderCounter(long window) { this.window = window; } void record(long ts) { if (!buckets.isEmpty() && buckets.peekLast()[0] == ts) buckets.peekLast()[1]++; else buckets.addLast(new long[]{ts, 1}); total++; } long count(long now) { while (!buckets.isEmpty() && buckets.peekFirst()[0] <= now - window) total -= buckets.pollFirst()[1]; return total; } }10 Cheapest route across a warehouse grid from the top-left to the bottom-right, moving only right or down.
mediumLet dp[j] hold the cheapest cost to reach column j of the current row. Entering a row, each cell's cost is its own value plus the smaller of coming from above (the old dp[j]) or from the left (dp[j-1] just computed). One row of storage suffices, giving O(rows x cols) time and O(cols) space. Initialising the whole first row to zero rather than infinity lets paths start in the wrong place, and forgetting that the first column only has an upper neighbour is a common slip.
pythondef min_path(grid): n = len(grid[0]) dp = [float('inf')] * n dp[0] = 0 for row in grid: dp[0] += row[0] for j in range(1, n): dp[j] = min(dp[j], dp[j - 1]) + row[j] return dp[-1]javastatic int minPath(int[][] grid) { int n = grid[0].length; int[] dp = new int[n]; java.util.Arrays.fill(dp, Integer.MAX_VALUE / 2); dp[0] = 0; for (int[] row : grid) { dp[0] += row[0]; for (int j = 1; j < n; j++) dp[j] = Math.min(dp[j], dp[j - 1]) + row[j]; } return dp[n - 1]; }
Frequently asked questions
Does Nykaa test beauty or retail knowledge in its coding round?
Nothing sourced suggests it does. The retail setting in this set is a way to practise recognising patterns. The underlying techniques are standard ones.
How should I practise when I do not know the exact format?
Build a mixed weekly routine: two array or string problems, one graph or DP problem, one small design. That covers the usual range of company tests without guessing at a specific paper.
When is a linear scan acceptable?
When the input is small enough, a few thousand items for most tests. State the limit you are assuming, then mention the faster structure you would switch to if the data grew.
What do I do when I cannot find the pattern in a problem?
Solve it by hand on a tiny example, write down what you did at each step, and look for the repeated operation. That operation usually points to the data structure.
Related guides
More in Company Interview Questions
- Nykaa Interview Questions and Answers
- Ola Coding Round Questions with Solutions
- Ola Interview Questions and Answers
- Oracle Coding Round Questions with Solutions in Python and Java
- Oracle Interview Questions and Answers for SDE Roles
- PayPal coding round questions with solutions
- PayPal interview questions with answers (software engineer, India)
- Paytm Coding Round Questions with Solutions
- Paytm Interview Questions and Answers
- Persistent Systems Coding Round Questions with Solutions
- Persistent Systems Interview Questions for Freshers
- PhonePe Coding Round Questions with Solutions