Trains the technique from
LeetCode 567Permutation in StringThis 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 seed catalogue codes every variety with a single lowercase letter. The string packet lists the seeds inside one packet, and the string row lists, in planting order, the seeds a gardener has already put in the ground along a long bed.
The gardener wants to know whether some unbroken stretch of the bed was planted from exactly one packet's worth of seed: a stretch qualifies when it holds the same varieties as packet in the same quantities, planted in whatever order. Return true if such a stretch exists in row, and false if none does.
Quantities count. A packet with two a seeds does not match a stretch holding one a and two b seeds, even though both draw on the same two varieties.
Example 1
The three seeds planted at positions 2 through 4 are one of each variety, matching the packet in a different order.
Example 2
Every three-seed stretch either includes a z or holds one a and two b seeds, while the packet holds two a and one b.
Example 3
The qualifying stretch is the final pair of seeds, so the last stretch of the bed has to be examined too.
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 contains_packet_window(packet: str, row: str) -> bool:public boolean containsPacketWindow(String packet, String row)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.