Skip to content

Latest commit

 

History

History

[20437]문자열 게임 2

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
file name src tags done draft level difficulty date
20437.md
문자열 게임 2
슬라이딩 윈도우
문자열
true
false
11
Gold V
2021-11-06

문자열 게임 2

import sys
from collections import defaultdict


def input(): return sys.stdin.readline().rstrip()


for _ in range(int(input())):
    chars = defaultdict(list)
    alphabet_count = [-1]*26

    text = input()
    K = int(input())

    # 전처리
    for idx, c in enumerate(text):
        m = ord(c)-ord('a')
        if alphabet_count[m] < 0:
            alphabet_count[m] = text.count(c)
        count = alphabet_count[m]

        if K <= count:
            chars[c].append(idx)
    # -
    _min, _max = 10000, 0
    for x in chars.values():
        for i in range(len(x)-K+1):
            # 0+k-1 2,
            current_length = x[i+K-1] - x[i] + 1
            _min = min(_min, current_length)
            _max = max(_max, current_length)

    if len(chars) > 0:
        print(_min, _max)
    else:
        print("-1")