public int solution(int[] stones, int k) {
int answer = 0;
int min = 1;
int max = 200000000;
while (min <= max) {
int mid = (min + max) / 2;
if (canCross(stones, k, mid)) {
min = mid + 1;
answer = Math.max(answer, mid);
} else {
max = mid - 1;
}
}
return answer;
}
boolean canCross(int[] stones, int k, int friendsNum) {
int consecutiveSkips = 0;
for (int stone : stones) {
consecutiveSkips = (stone - friendsNum < 0) ? consecutiveSkips + 1 : 0;
if (consecutiveSkips == k) {
return false;
}
}
return true;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/64062