문제
https://www.acmicpc.net/problem/20922
코드
import sys
input=sys.stdin.readline
n,k=map(int, input().split())
array=list(map(int, input().split()))
left,right=0,0
count=[0]*(max(array)+1)
result=0
while right<n:
if count[array[right]]<k:
count[array[right]] += 1
right+=1
else:
count[array[left]] -= 1
left+=1
result=max(result,right-left)
print(result)
시간 복잡도
길이가 N인 수열을 순회하므로 O(N)
'문제풀이 > 기타' 카테고리의 다른 글
[파이썬] [분할정복] 백준 1074 Z (0) | 2023.04.03 |
---|---|
[파이썬] [슬라이딩] 백준 1522 문자열 교환 (0) | 2023.03.16 |
[파이썬] [백트래킹] 백준 7490 0 만들기 (0) | 2023.02.19 |
[파이썬] [백트래킹] 백준 22251 빌런 호석 (0) | 2023.02.17 |
[파이썬] [스택] 백준 1863 스카이라인 (0) | 2023.02.15 |