Find Every Scan Log Position Holding a Scrambled SKU Code

Last updated: November 29, 2026

Quick Overview

Given a long scan log string and a short SKU code, return every starting index in the log where some rearrangement of the SKU code's characters appears as a contiguous substring.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a long scan log string and a short SKU code, return every starting index in the log where some rearrangement of the SKU code's characters appears as a contiguous substring.

An Amazon technical screen question about matching garbled barcode scans to a known SKU. The interviewer checks for a fixed-size window with character counts and an O(1) match test using a counter of satisfied characters rather than comparing full maps each step.

What the Interviewer Expects
  • Use a window the same length as the SKU code
  • Keep character counts for the code and the window
  • Update counts incrementally as the window slides
  • Track how many characters currently match to compare in O(1)
  • Return all starting indices in increasing order
Key Topics to Cover
Fixed Sliding Window
Frequency Counting
Anagrams
Strings
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 code may contain wildcard characters that match anything?
  • How would you search for many SKU codes at once?
  • What if the log arrives as a stream and you must emit matches online?
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: strings log and code over uppercase letters and digits. Output: sorted list of indices i such that log[i:i+len(code)] is a permutation of code. If the code is longer than the log, retur...

High-Level Design

Keep one counter diff[ch] = need[ch] - window[ch], seeded with the code's counts, and a single integer off holding how many characters currently have a non-zero diff. Slide a window of length m ov...


Submit Your Answer
Markdown supported