Find the Longest Run of In-Stock Sizes for a Shoe
Last updated: November 29, 2026
Quick Overview
Given a shoe's ordered size chart (including half sizes) and a map from size to units in stock, return the first and last size of the longest contiguous run of sizes that are all in stock. Return None if nothing is in stock.
Nike
November 29, 20260
0
0 solved
Given a shoe's ordered size chart (including half sizes) and a map from size to units in stock, return the first and last size of the longest contiguous run of sizes that are all in stock. Return None if nothing is in stock.
A warm-up in the style of a Nike phone screen for a commerce or product-page team, where the size picker and 'low stock' messaging depend on per-size inventory. The interviewer is checking clean single-pass iteration, careful handling of missing keys and tie rules, and whether you ask how the size chart is ordered.
What the Interviewer Expects
- Asks whether the size chart is already ordered and whether missing sizes mean zero stock
- Uses a single pass with a running streak rather than nested loops
- States and implements a tie rule (first longest run wins)
- Handles the empty and single-size cases
- Explains O(n) time and O(1) extra space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return all runs of length at least k for a 'wide size availability' badge?
- Sizes come from different regional charts (US, UK, EU). How do you keep the order correct?
- How would you answer this for 10,000 styles where stock changes every few seconds?
- What if a size is considered in stock only when units exceed a safety buffer?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: size_chart, an ordered list such as [7, 7.5, 8, ...], and stock, a dict from size to units. A size missing from stock counts as zero. Output: a tuple (first_size, last_size) for the l...
High-Level Design
Walk the chart once, keeping the start index and length of the current in-stock streak. Whenever the current streak grows past the best seen so far, record it. An out-of-stock size resets the streak. ...