Myntra Coding Round Questions with Solutions
Last updated 2026-11-19
Myntra is a fashion marketplace, so its natural data is a catalogue: products with sizes and colours, outfits assembled from tops and bottoms, trending hashtags and a product grid that has to be laid out on screen. One third-party page describing the Rampup internship assessment mentions fifteen multiple-choice questions plus two coding questions, which suggests short, clean medium problems rather than sprawling ones.
The ten exercises below use that fashion-catalogue setting. They are practice problems written for this page, not past questions. Afterwards read Myntra interview questions for design and HR material, and the online assessment guide for pacing a short test.
Pacing a short assessment with two coding questions
Do not neglect the multiple-choice items; they are quick marks and a few minutes there is cheap. Then read both coding questions and start with the one whose approach you could state in a single sentence. A working solution to one beats two half-finished attempts.
Before submitting, run your code on the sample and then on a tiny hostile input: an empty list, one element, all values equal. Short tests are often lost on a missed edge rather than a wrong idea. The fourth and tenth problems below are small enough to rehearse that habit in minutes.
Hiring status
Sourced programmes are listed at Myntra hiring, and openings are at careers.myntra.com. The assessment shape above comes from a third-party listing and may differ for your programme or year.
Myntra Coding Round Questions with Solutions: questions with worked answers
1 Filter a catalogue by any of several sizes, any of several colours and a maximum price.
easyEach facet works the same way: if the shopper selected nothing for it, it imposes no constraint; otherwise the product must match at least one selected value. Represent selections as sets, test overlap with a set intersection, and combine the three facets with AND. O(products x selected values) overall. The usual bug is treating an empty selection as 'match nothing', which empties the page when the shopper has not yet chosen a colour.
pythondef filter_catalogue(products, sizes=(), colours=(), max_price=None): sz, co = set(sizes), set(colours) return [p for p in products if (not sz or sz & p['sizes']) and (not co or p['colour'] in co) and (max_price is None or p['price'] <= max_price)]javaimport java.util.*; import java.util.stream.*; record Product(String id, Set<String> sizes, String colour, int price) {} static List<Product> filterCatalogue(List<Product> products, Set<String> sizes, Set<String> colours, Integer maxPrice) { return products.stream() .filter(p -> sizes.isEmpty() || !Collections.disjoint(sizes, p.sizes())) .filter(p -> colours.isEmpty() || colours.contains(p.colour())) .filter(p -> maxPrice == null || p.price() <= maxPrice) .collect(Collectors.toList()); }2 Recommend the stocked size closest to a shopper's body measurement.
mediumKeep the available sizes sorted and binary-search for the first size not smaller than the measurement. The answer is either that size or the one just before it; pick whichever is nearer and prefer the smaller on a tie. Handle the two ends, where only one neighbour exists. O(log n) per query. Scanning the whole list works for small stock but loses marks when the interviewer asks for a faster version, and forgetting the boundary cases throws an index error.
pythonimport bisect def closest_size(sizes, x): i = bisect.bisect_left(sizes, x) if i == 0: return sizes[0] if i == len(sizes): return sizes[-1] before, after = sizes[i - 1], sizes[i] return before if x - before <= after - x else afterjavastatic int closestSize(int[] sizes, int x) { int lo = 0, hi = sizes.length; while (lo < hi) { int mid = (lo + hi) >>> 1; if (sizes[mid] < x) lo = mid + 1; else hi = mid; } if (lo == 0) return sizes[0]; if (lo == sizes.length) return sizes[sizes.length - 1]; return x - sizes[lo - 1] <= sizes[lo] - x ? sizes[lo - 1] : sizes[lo]; }3 Count top-and-bottom pairs whose combined price fits within a budget.
mediumSort both price lists. Walk the tops from cheapest to dearest while a pointer into the bottoms only ever moves down: for each top, retreat the pointer until the bottom at that position fits the remaining budget; every bottom up to it also fits, so add the pointer position to the count. Sorting dominates at O(n log n + m log m), and the walk is linear. Checking every pair is O(n x m) and the usual first attempt.
pythondef count_outfits(tops, bottoms, budget): tops, bottoms = sorted(tops), sorted(bottoms) j, total = len(bottoms), 0 for t in tops: while j > 0 and bottoms[j - 1] + t > budget: j -= 1 total += j return totaljavaimport java.util.*; static long countOutfits(int[] tops, int[] bottoms, int budget) { int[] t = tops.clone(), b = bottoms.clone(); Arrays.sort(t); Arrays.sort(b); int j = b.length; long total = 0; for (int x : t) { while (j > 0 && b[j - 1] + x > budget) j--; total += j; } return total; }4 Sort an array of colour tags that are only 0, 1 or 2 in a single pass without extra space.
easyUse three regions with pointers: everything before low is 0, everything after high is 2, and mid scans the unknown middle. A 0 swaps with low and both advance; a 1 just advances mid; a 2 swaps with high and only high retreats, because the swapped-in value is unexamined. One pass, O(n) time, O(1) space. The frequent error is advancing mid after swapping with high, which skips the new element.
pythondef sort_tags(a): lo, mid, hi = 0, 0, len(a) - 1 while mid <= hi: if a[mid] == 0: a[lo], a[mid] = a[mid], a[lo] lo += 1 mid += 1 elif a[mid] == 1: mid += 1 else: a[mid], a[hi] = a[hi], a[mid] hi -= 1javastatic void sortTags(int[] a) { int lo = 0, mid = 0, hi = a.length - 1; while (mid <= hi) { if (a[mid] == 0) { int t = a[lo]; a[lo++] = a[mid]; a[mid++] = t; } else if (a[mid] == 1) mid++; else { int t = a[mid]; a[mid] = a[hi]; a[hi--] = t; } } }5 List every outfit with one item from each category whose total price stays within a budget.
mediumBacktrack category by category, adding one item at a time and recursing. Prune early: precompute the cheapest remaining item for each later category and abandon a branch when the cost so far plus that minimum already exceeds the budget. Worst case is the product of the category sizes, but pruning removes most dead branches. Common errors are forgetting to undo the choice after recursing, and copying the list only at the end so every outfit ends up sharing one mutated list.
pythondef outfits(categories, budget): # categories: list of [(name, price), ...] n = len(categories) cheapest = [0] * (n + 1) for i in range(n - 1, -1, -1): cheapest[i] = cheapest[i + 1] + min(p for _, p in categories[i]) result, chosen = [], [] def go(i, cost): if i == n: result.append(list(chosen)) return for name, price in categories[i]: if cost + price + cheapest[i + 1] > budget: continue chosen.append(name) go(i + 1, cost + price) chosen.pop() go(0, 0) return resultjavaimport java.util.*; static List<List<String>> outfits(String[][] names, int[][] prices, int budget) { int n = names.length; int[] cheapest = new int[n + 1]; for (int i = n - 1; i >= 0; i--) { int m = Integer.MAX_VALUE; for (int p : prices[i]) m = Math.min(m, p); cheapest[i] = cheapest[i + 1] + m; } List<List<String>> result = new ArrayList<>(); go(0, 0, names, prices, budget, cheapest, new ArrayList<>(), result); return result; } private static void go(int i, int cost, String[][] names, int[][] prices, int budget, int[] cheapest, List<String> chosen, List<List<String>> out) { if (i == names.length) { out.add(new ArrayList<>(chosen)); return; } for (int k = 0; k < names[i].length; k++) { if (cost + prices[i][k] + cheapest[i + 1] > budget) continue; chosen.add(names[i][k]); go(i + 1, cost + prices[i][k], names, prices, budget, cheapest, chosen, out); chosen.remove(chosen.size() - 1); } }6 Read a product grid in spiral order for a layout preview.
mediumKeep four boundaries: top, bottom, left and right. Walk the top row left to right and shrink top, the right column downwards and shrink right, then the bottom row right to left if rows remain, and the left column upwards if columns remain. Repeat until the boundaries cross. Each cell is visited once, so O(rows x cols). The two guard checks before the last two walks are what stop single-row and single-column grids from emitting cells twice.
pythondef spiral(m): if not m or not m[0]: return [] out = [] top, bot, left, right = 0, len(m) - 1, 0, len(m[0]) - 1 while top <= bot and left <= right: out.extend(m[top][left:right + 1]) top += 1 out.extend(m[r][right] for r in range(top, bot + 1)) right -= 1 if top <= bot: out.extend(m[bot][c] for c in range(right, left - 1, -1)) bot -= 1 if left <= right: out.extend(m[r][left] for r in range(bot, top - 1, -1)) left += 1 return outjavaimport java.util.*; static List<Integer> spiral(int[][] m) { List<Integer> out = new ArrayList<>(); if (m.length == 0 || m[0].length == 0) return out; int top = 0, bot = m.length - 1, left = 0, right = m[0].length - 1; while (top <= bot && left <= right) { for (int c = left; c <= right; c++) out.add(m[top][c]); top++; for (int r = top; r <= bot; r++) out.add(m[r][right]); right--; if (top <= bot) { for (int c = right; c >= left; c--) out.add(m[bot][c]); bot--; } if (left <= right) { for (int r = bot; r >= top; r--) out.add(m[r][left]); left++; } } return out; }7 Return the k most frequent hashtags, breaking ties alphabetically.
mediumCount occurrences with a hash map, then select the k best by the key (negative count, word). A heap of size k gives O(n log k); sorting every distinct tag gives O(d log d) and is fine when k is close to d. In Java, keep a min-heap whose top is the currently worst of the best k, so each new candidate either replaces it or is dropped. Sorting by count alone yields unstable tie order, and the alphabetical tie-break is the clause people skim past.
pythonimport heapq from collections import Counter def trending(tags, k): cnt = Counter(tags) return heapq.nsmallest(k, cnt, key=lambda w: (-cnt[w], w))javaimport java.util.*; static List<String> trending(List<String> tags, int k) { Map<String, Integer> cnt = new HashMap<>(); for (String t : tags) cnt.merge(t, 1, Integer::sum); PriorityQueue<String> pq = new PriorityQueue<>( (a, b) -> cnt.get(a).equals(cnt.get(b)) ? b.compareTo(a) : cnt.get(a) - cnt.get(b)); for (String w : cnt.keySet()) { pq.add(w); if (pq.size() > k) pq.poll(); } LinkedList<String> out = new LinkedList<>(); while (!pq.isEmpty()) out.addFirst(pq.poll()); return out; }8 Compress a banner string in place so that runs become a letter followed by the run length.
easyUse a read pointer that finds each run and a write pointer that stores the letter and, when the run is longer than one, its decimal digits. The write pointer can never overtake the read pointer, so no extra array is needed; return the new length. O(n) time, O(1) space. Runs of ten or more must write several digit characters, which is the case most solutions forget, and a run of one must not get a count of 1.
pythondef compress(chars): w = i = 0 n = len(chars) while i < n: j = i while j < n and chars[j] == chars[i]: j += 1 chars[w] = chars[i] w += 1 if j - i > 1: for d in str(j - i): chars[w] = d w += 1 i = j return wjavastatic int compress(char[] chars) { int w = 0, i = 0, n = chars.length; while (i < n) { int j = i; while (j < n && chars[j] == chars[i]) j++; chars[w++] = chars[i]; if (j - i > 1) for (char d : String.valueOf(j - i).toCharArray()) chars[w++] = d; i = j; } return w; }9 Median price across two sorted price lists in logarithmic time.
hardBinary-search the cut position in the shorter list. A cut of i items from list A and j from list B, with i + j equal to half the total, is correct when the largest left element of each list is no more than the smallest right element of the other. Move the cut left or right depending on which side breaks the rule, using infinities for empty sides. O(log(min(m, n))). Merging the lists is O(m + n) and is what this question exists to beat.
pythondef median_two(a, b): if len(a) > len(b): a, b = b, a m, n = len(a), len(b) lo, hi, half = 0, m, (m + n + 1) // 2 inf = float('inf') while lo <= hi: i = (lo + hi) // 2 j = half - i a_left = a[i - 1] if i > 0 else -inf a_right = a[i] if i < m else inf b_left = b[j - 1] if j > 0 else -inf b_right = b[j] if j < n else inf if a_left <= b_right and b_left <= a_right: if (m + n) % 2: return max(a_left, b_left) return (max(a_left, b_left) + min(a_right, b_right)) / 2 if a_left > b_right: hi = i - 1 else: lo = i + 1javastatic double medianTwo(int[] a, int[] b) { if (a.length > b.length) { int[] t = a; a = b; b = t; } int m = a.length, n = b.length, lo = 0, hi = m, half = (m + n + 1) / 2; while (lo <= hi) { int i = (lo + hi) / 2, j = half - i; int aL = i > 0 ? a[i - 1] : Integer.MIN_VALUE, aR = i < m ? a[i] : Integer.MAX_VALUE; int bL = j > 0 ? b[j - 1] : Integer.MIN_VALUE, bR = j < n ? b[j] : Integer.MAX_VALUE; if (aL <= bR && bL <= aR) { if ((m + n) % 2 == 1) return Math.max(aL, bL); return (Math.max(aL, bL) + (double) Math.min(aR, bR)) / 2; } if (aL > bR) hi = i - 1; else lo = i + 1; } return 0; }10 Design a set with O(1) insert, delete and pick-a-random-element, for a style-of-the-day carousel.
mediumStore the elements in a dynamic array and keep a map from element to its array index. Insert appends and records the index. Delete moves the last array element into the deleted slot, updates that element's index in the map, then pops the tail, so no gap is left. Picking a random element is a random index into the array. All three are O(1) on average. A plain hash set cannot pick uniformly in constant time, and deleting from the middle of a list is O(n).
pythonimport random class RandomSet: def __init__(self): self.items, self.pos = [], {} def insert(self, x): if x in self.pos: return False self.pos[x] = len(self.items) self.items.append(x) return True def remove(self, x): if x not in self.pos: return False i = self.pos.pop(x) last = self.items.pop() if i < len(self.items): self.items[i] = last self.pos[last] = i return True def pick(self): return random.choice(self.items)javaimport java.util.*; class RandomSet { private final List<Integer> items = new ArrayList<>(); private final Map<Integer, Integer> pos = new HashMap<>(); private final Random rnd = new Random(); boolean insert(int x) { if (pos.containsKey(x)) return false; pos.put(x, items.size()); items.add(x); return true; } boolean remove(int x) { Integer i = pos.remove(x); if (i == null) return false; int last = items.remove(items.size() - 1); if (i < items.size()) { items.set(i, last); pos.put(last, i); } return true; } int pick() { return items.get(rnd.nextInt(items.size())); } }
Frequently asked questions
Is the Myntra assessment the same for interns and full-time hires?
Not necessarily. The format quoted here comes from a third-party page about the internship assessment, so confirm your own programme's format in the invite you receive.
How should I split time between the MCQs and the coding questions?
Clear the multiple-choice items quickly, then give most of the remaining time to coding. If a coding question stalls for ten minutes, move to the other and come back.
Which topics deserve the most practice for a two-question test?
Arrays, strings, hash maps and basic trees at medium difficulty, plus binary search and sorting variants. These problems cover each of those with a catalogue flavour.
What edge cases should I always test before submitting?
An empty input, a single element, all-equal values and the largest allowed size. Writing these four down before coding takes under a minute and catches most avoidable failures.
Sources
Related guides
More in Company Interview Questions
- Myntra Interview Questions and Answers
- Nagarro coding round questions
- Nagarro interview questions and answers
- Netflix Coding Round Questions with Solutions in Python and Java
- 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