본문 바로가기

hacking sorcerer

do you like beef ?

728x90
반응형

def shortest_full_distinct_window(s: str) -> int:
    target = set(s)
    need = len(target)

    count = {}
    start = 0
    have = 0
    best = float("inf")

    for end, ch in enumerate(s):
        count[ch] = count.get(ch, 0) + 1
        if count[ch] == 1:
            have += 1

        while have == need:
            best = min(best, end - start + 1)

            left = s[start]
            count[left] -= 1
            if count[left] == 0:
                have -= 1
                # optional: del count[left]
            start += 1

    return -1 if best == float("inf") else best


s = input().strip()
print(shortest_full_distinct_window(s))

728x90
반응형

'hacking sorcerer' 카테고리의 다른 글

scavenger_hunt.py  (0) 2025.12.24
duplicated_zero.py  (0) 2025.12.23
🥷MINJA  (0) 2025.12.19
hacker reverse  (0) 2025.12.18
tryhackme bankgpt  (0) 2025.12.17