Trains the technique from
LeetCode 76Minimum Window SubstringThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A conveyor carries parts past an assembly cell in a fixed order. The string belt records the stamp on each part, one letter per part, reading along the belt. A kit order is written as the string kit: every letter in it is a stamp the kit needs, and a letter written twice means the kit needs two parts carrying that stamp. Stamps are case sensitive, so a part stamped b cannot fill a slot that asks for B.
Find the shortest unbroken stretch of the belt that can fill the whole kit and return that stretch as a string. Extra parts inside the stretch are set aside and cost nothing, but a stretch may not skip over parts. If several stretches tie for shortest, return the one that starts earliest along the belt. If no stretch can fill the kit, return an empty string.
The cell is fed at line rate, so your work must stay proportional to the combined length of belt and kit.
Example 1
The first two parts already carry both stamps the kit asks for, and no single part can fill a two-stamp kit.
Example 2
The kit lists b twice, so the stretch has to reach across both b parts as well as one a and one c.
Example 3
Two stretches of length two can fill the kit, and the earlier of the two is the answer.
Example 4
No part on the belt carries the stamp z, so nothing can fill the kit.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def shortest_kit_stretch(belt: str, kit: str) -> str:public String shortestKitStretch(String belt, String kit)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.