NNeedleThyme
Workflows

Coding workflows · Minimum covering substrings

03
Built around your work

A concrete starting point

Find the shortest substring covering required character counts within two strings of at most 1024 code points. Check empty requirements and absent matches, choosing the leftmost tie without Unicode normalization.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Minimum covering substrings

A concrete starting point
from collections import Counter

def covering_window(text, required):
    if type(text) is not str or type(required) is not str or max(len(text), len(required)) > 1024:
        raise ValueError("window.input")
    if not required:
        return ""
    need, missing, left, best = Counter(required), len(required), 0, None
    for right, char in enumerate(text, 1):
        if need[char] > 0:
            missing -= 1
        need[char] -= 1
        while missing == 0:
            if best is None or right-left < best[1]-best[0]:
                best = (left, right)
            old = text[left]
            need[old] += 1
            if need[old] > 0:
                missing += 1
            left += 1
    return "" if best is None else text[best[0]:best[1]]

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗