NNeedleThyme
Product

Product features · Minimum covering substrings

01

Use covering_window.py to review whether every required character count is covered by the shortest leftmost result.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Minimum covering substrings

● ● ●NeedleThyme●
A concrete starting point · Minimum covering substrings ×
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]]
✳Minimum covering substrings
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗