# 징검다리 건너기 - 프로그래머스
def solution(stones, k):
s, e = 1, max(stones)
ret = 1
while s <= e:
mid = (s + e) // 2
zero_num = 0
flag = False
for stone in stones:
if stone < mid:
zero_num += 1
if zero_num == k:
flag = True
break
else:
zero_num = 0
if flag:
e = mid - 1
else:
ret = max(ret, mid)
s = mid + 1
return ret