Finding minimum substring with all chars Python

PHOTO EMBED

Tue Aug 16 2022 00:11:24 GMT+0000 (UTC)

Saved by @bryantirawan #python #codesignal

def solution(s, t):
    result = []
    for i in range(len(s)):
        if s[i] in t:
            coll = set()
            for j in range(i, len(s)):
                if s[j] in t:
                    coll.add(s[j])
                    if len(coll) == len(t):
                        result.append(s[i:j+1])
    if result:
        return min(result, key=len)
    
    return ""
    


content_copyCOPY

Probably can do with regex as well

https://app.codesignal.com/interview-practice/task/rFeSD5rNy9RxfLcqg/description