Created
April 8, 2020 13:33
-
-
Save inspirit941/f73344fdc7d2a3527dfa371ad0838b6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(stones, k): | |
_min, _max = 0, max(stones) | |
answer = 0 | |
while _min <= _max: | |
mid = (_min + _max) // 2 | |
arr = [] | |
zero_in_row = 0 | |
max_zeros = zero_in_row | |
for i in range(len(stones)): | |
if stones[i] >= mid: | |
arr.append(stones[i]) | |
elif stones[i] < mid: | |
arr.append(0) | |
if arr[i] == 0: | |
zero_in_row += 1 | |
elif arr[i] != 0: | |
max_zeros = max(max_zeros, zero_in_row) | |
zero_in_row = 0 | |
max_zeros = max(max_zeros, zero_in_row) | |
if max_zeros >= k: | |
_max = mid - 1 | |
else: | |
answer = mid | |
_min = mid + 1 | |
return answer | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment