https://programmers.co.kr/learn/courses/30/lessons/64062
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
def solution(stones, k):
start = 0
end = max(stones)
while start <= end:
mid = int((start + end) / 2)
count = 0
for stone in stones:
if count == k:
break
if stone <= mid:
count += 1
else:
count = 0
if count == k:
end = mid - 1
result = mid
else:
start = mid + 1
return result
Complexity
$O(|\text{stones}| \cdot log |\text{max(stones)}|)$
PREVIOUSEtc