Autocoder

Walmart Coding Round Questions With Solutions

Last updated 2026-11-19

The sourced format of Walmart Global Tech campus coding challenges, such as Sparkplug, is two problems in 90 minutes in any language, after an MCQ stage on reasoning, DSA, OOP and OS. That favours medium-difficulty problems solved cleanly under time pressure. The eleven problems below are practice in that style, not real papers.

Each has the idea, code, complexity and the mistakes that usually cost marks. For interview-style questions see Walmart interview questions, and for pacing see how to crack a DSA coding round.

Sourced format2 problems, 90 minutes, any language (Sparkplug 2026)
Before itMCQ stage on reasoning, DSA, OOP, OS

How to use the 90 minutes

With two problems, read both first and start with the one whose approach you can see immediately. Aim for a correct brute force in the first 10 minutes, then optimise. Partial credit is usually earned by passing test cases, so a working O(n squared) solution beats an unfinished O(n) one.

Patterns that recur

Hash maps and sliding windows on strings and arrays, interval problems, BFS and DFS on grids, topological ordering, and one-dimensional dynamic programming cover most medium problems. Retail-flavoured wording such as orders, inventory or delivery slots usually hides one of these patterns.

Hiring status

Walmart tests have run on Unstop in earlier cycles; the sourced Sparkplug 2026 coding challenge had 2 problems in 90 minutes. For the current state of openings read the Walmart hiring page or the Walmart Global Tech careers site. See how to crack the Walmart interview for the process.

Walmart Coding Round Questions With Solutions: questions with worked answers

  1. 1

    Longest substring without repeating characters.

    easy

    Slide a window with a map of the last index of each character. When the current character was seen inside the window, move the left edge past that index. Track the maximum length. Mistake: moving left backwards when the stored index is already outside the window; use max.

    python
    def longest_unique(s):
        last, left, best = {}, 0, 0
        for i, ch in enumerate(s):
            if ch in last and last[ch] >= left:
                left = last[ch] + 1
            last[ch] = i
            best = max(best, i - left + 1)
        return best
    java
    static int longestUnique(String s) {
        java.util.Map<Character,Integer> last = new java.util.HashMap<>();
        int left = 0, best = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (last.containsKey(c) && last.get(c) >= left) left = last.get(c) + 1;
            last.put(c, i);
            best = Math.max(best, i - left + 1);
        }
        return best;
    }
  2. 2

    Merge overlapping delivery slots (merge intervals).

    easy

    Sort by start. Keep a result list; if the next interval starts at or before the end of the last one, extend the end with max, otherwise append. Time O(n log n), space O(n). Mistake: forgetting that a nested interval must not shrink the end.

    python
    def merge(intervals):
        intervals.sort()
        out = []
        for s, e in intervals:
            if out and s <= out[-1][1]:
                out[-1][1] = max(out[-1][1], e)
            else:
                out.append([s, e])
        return out
  3. 3

    Number of islands in a grid of 0s and 1s.

    medium

    Scan every cell; on an unvisited 1, count one island and flood-fill it. Use an explicit stack to avoid recursion limits on large grids. Time O(rows times cols), space O(rows times cols) worst case. Mistake: Python recursion depth exceeding the limit on a big grid.

    python
    def islands(g):
        R, C, n = len(g), len(g[0]), 0
        for r in range(R):
            for c in range(C):
                if g[r][c] == 1:
                    n += 1
                    g[r][c] = 0
                    st = [(r, c)]
                    while st:
                        x, y = st.pop()
                        for dx, dy in ((1,0),(-1,0),(0,1),(0,-1)):
                            a, b = x + dx, y + dy
                            if 0 <= a < R and 0 <= b < C and g[a][b] == 1:
                                g[a][b] = 0
                                st.append((a, b))
        return n
  4. 4

    Design an LRU cache with O(1) get and put.

    medium

    Combine a hash map with a doubly linked list. The map points to nodes; the list orders them from most to least recently used. On get, move the node to the front. On put, insert at the front and evict the tail when over capacity. In Python an OrderedDict gives this directly; in Java LinkedHashMap with accessOrder true and removeEldestEntry does the same.

    python
    from collections import OrderedDict
    
    class LRU:
        def __init__(self, cap):
            self.cap, self.d = cap, OrderedDict()
        def get(self, k):
            if k not in self.d:
                return -1
            self.d.move_to_end(k)
            return self.d[k]
        def put(self, k, v):
            self.d[k] = v
            self.d.move_to_end(k)
            if len(self.d) > self.cap:
                self.d.popitem(last=False)
    java
    class LRU<K,V> extends java.util.LinkedHashMap<K,V> {
        private final int cap;
        LRU(int cap) { super(16, 0.75f, true); this.cap = cap; }
        protected boolean removeEldestEntry(java.util.Map.Entry<K,V> e) { return size() > cap; }
    }
  5. 5

    Top K frequent elements.

    medium

    Count with a map, then use a min-heap of size k, or bucket by frequency. The heap gives O(n log k); bucket sort gives O(n) because frequencies are at most n. Mistake: sorting the whole map, which is fine but slower than asked.

    python
    import heapq
    from collections import Counter
    
    def top_k(nums, k):
        return [x for x, _ in heapq.nlargest(k, Counter(nums).items(), key=lambda t: t[1])]
  6. 6

    Course schedule: can all courses be finished given prerequisites?

    medium

    Build a directed graph and run Kahn topological sort: repeatedly remove nodes with indegree zero. If all nodes are removed there is no cycle. Time O(V + E). Mistake: building edges in the wrong direction, which does not change the answer here but breaks the ordering variant. See graph interview questions.

    python
    from collections import deque
    
    def can_finish(n, prereq):
        adj = [[] for _ in range(n)]
        indeg = [0] * n
        for a, b in prereq:      # b must come before a
            adj[b].append(a)
            indeg[a] += 1
        q = deque(i for i in range(n) if indeg[i] == 0)
        seen = 0
        while q:
            u = q.popleft()
            seen += 1
            for v in adj[u]:
                indeg[v] -= 1
                if indeg[v] == 0:
                    q.append(v)
        return seen == n
  7. 7

    Coin change: fewest coins to make an amount.

    medium

    Let dp[x] be the minimum coins for amount x, dp[0] = 0. For each x take the minimum of dp[x - c] + 1 over coins c. Return -1 if dp[amount] is still infinity. Time O(amount times coins), space O(amount). Mistake: greedy choice of the largest coin, which fails for coins like 1, 3, 4 and amount 6.

    python
    def coin_change(coins, amount):
        INF = float('inf')
        dp = [0] + [INF] * amount
        for x in range(1, amount + 1):
            for c in coins:
                if c <= x and dp[x - c] + 1 < dp[x]:
                    dp[x] = dp[x - c] + 1
        return -1 if dp[amount] == INF else dp[amount]
  8. 8

    Product of array except self, without division.

    medium

    Build prefix products left to right into the answer array, then multiply by a running suffix product right to left. Time O(n), extra space O(1) beyond the output. Mistake: using division, which breaks when the array contains zero.

    python
    def product_except_self(a):
        n = len(a)
        out = [1] * n
        p = 1
        for i in range(n):
            out[i] = p
            p *= a[i]
        s = 1
        for i in range(n - 1, -1, -1):
            out[i] *= s
            s *= a[i]
        return out
  9. 9

    Search in a rotated sorted array.

    medium

    Binary search where at least one half is always sorted. If the left half is sorted and the target lies in it, search left; otherwise search right, and mirror the logic. Time O(log n). Mistake: using strict less-than instead of less-than-or-equal when comparing a[lo] with a[mid], which fails for two-element ranges.

    python
    def search(a, t):
        lo, hi = 0, len(a) - 1
        while lo <= hi:
            mid = (lo + hi) // 2
            if a[mid] == t:
                return mid
            if a[lo] <= a[mid]:
                if a[lo] <= t < a[mid]:
                    hi = mid - 1
                else:
                    lo = mid + 1
            else:
                if a[mid] < t <= a[hi]:
                    lo = mid + 1
                else:
                    hi = mid - 1
        return -1
  10. 10

    Group anagrams.

    easy

    Key each word by its sorted letters, or by a 26-count tuple to get O(n times k) instead of O(n times k log k). Store words in a map from key to list. Mistake: using a list as a dictionary key; convert it to a tuple.

    python
    from collections import defaultdict
    
    def group_anagrams(words):
        g = defaultdict(list)
        for w in words:
            cnt = [0] * 26
            for ch in w:
                cnt[ord(ch) - 97] += 1
            g[tuple(cnt)].append(w)
        return list(g.values())
  11. 11

    Right side view of a binary tree.

    medium

    Do a level-order traversal and record the last node of each level. Time O(n), space O(width). A depth-first alternative visits right child first and records the first node seen at each new depth. Mistake: taking only the rightmost chain, which misses nodes that are visible because the right subtree is shorter.

    python
    from collections import deque
    
    def right_view(root):
        if not root:
            return []
        out, q = [], deque([root])
        while q:
            for i in range(len(q)):
                node = q.popleft()
                if node.left:
                    q.append(node.left)
                if node.right:
                    q.append(node.right)
            out.append(node.val)
        return out

Frequently asked questions

How many coding problems does the Walmart challenge have?

The sourced Sparkplug 2026 coding challenge had 2 problems in 90 minutes, in any language. Other roles may differ, so read your own invitation.

What difficulty should I practise?

Medium level problems on arrays, strings, graphs and dynamic programming, plus a few easy ones for speed.

Is the test proctored?

Details vary by event. Read the instructions on the platform you are given, and see is it safe for what monitoring can and cannot see.

Which language is best?

Any language the platform allows. Choose the one where you write correct code fastest.

Sources

Related guides

More in Company Interview Questions

See all in this section