Loading
Loading
A warehouse conveyor carries parts past a picker. A build requires a specific multiset of parts.
Return the length of the shortest contiguous run of the conveyor that contains every required part, counting multiplicity. Return 0 if no such run exists.
conveyor = "ADOBECODEBANC", required = "ABC"[ADOBEC]ODEBANCfirst valid window — length 6ADOBEC[ODEBA]NCstill valid at length 5? shrink furtherADOBECODEB[ANC]length 3? needs B — final answer 4 via BANC4Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n + m) time · O(alphabet) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
"BANC" is the shortest run holding A, B and C.
Example 2
Example 3
Two a's are required but only one is available.