leetle

Daily challenge for 2026-10-16

654. Shortest Segment Containing Required Tasks

You are given a string tasks representing a sequence of executed tasks and a string required containing distinct required task labels. The character '#' acts as an execution reset marker, meaning no valid segment may span across or contain '#'.

Find the length of the shortest contiguous substring in tasks that contains every label from required at least once and contains no reset marker '#'. If no such substring exists, return 0.

Constraints:
The task string has 0–2,000 characters, all lowercase ASCII letters or #. The required string is non-empty and contains distinct lowercase ASCII letters; it never contains #.

Example:
Input: tasks = "a#bca#cab", required = "abc"
Output: 3

Run this challenge interactively in Python or JavaScript when the app loads.