Gamified challenge · Variable sliding window
stalls[i] is the one item stall i sells (a letter), and need is your shopping list, also letters. A letter that appears twice in need means you need two stalls selling it.
Write minWindow(stalls, need) that returns the shortest run of consecutive stalls (a substring of stalls) that covers everything on the list. For stalls = "ADOBECODEBANC" and need = "ABC" the answer is "BANC". If no run covers the list, return "".
If several runs tie for shortest, any of them is accepted. Grow a window on the right until nothing is missing, then shrink it from the left while it still covers the list.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google