Shortest Aisle Walk Covering Every Item on a Shopping List

Last updated: November 29, 2026

Quick Overview

A store route is a list of product categories in aisle order. Given a shopping list of categories (with repeats meaning you need that many stops), return the start and end index of the shortest contiguous stretch of the route that covers the whole list, or None if impossible.

Walmart Labs
Coding & Algorithms
Software Engineer
Walmart Labs
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


A store route is a list of product categories in aisle order. Given a shopping list of categories (with repeats meaning you need that many stops), return the start and end index of the shortest contiguous stretch of the route that covers the whole list, or None if impossible.

Framed around in-store pick paths for Walmart online grocery pickup, where associates walk aisles to fill orders. Interviewers in the Walmart Labs onsite loop look for a correct variable-size sliding window with multiplicity, plus clean reasoning about when the window is valid.

What the Interviewer Expects
  • Recognize the minimum covering window pattern
  • Track required counts with multiplicity, not just presence
  • Maintain a single missing counter so validity checks are O(1)
  • Shrink from the left only while the window stays valid
  • Prove each index enters and leaves the window once
Key Topics to Cover
sliding window
hash maps
two pointers
counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if the route is circular, so the walk can wrap past the last aisle?
  • How would you return all minimum windows instead of one?
  • What if each aisle has a walking cost and you minimize total cost rather than count?
  • How would you handle a stream of aisle events with unknown length?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: route, a list of category strings, and needed, a list where a category repeated twice means two separate stops are required. Output: inclusive (start, end) of the shortest covering window...

High-Level Design

Use a sliding window. need[c] holds how many more units of category c the window still requires; it can go negative when the window holds surplus. A single integer missing counts outstanding units...


Submit Your Answer
Markdown supported