<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Sliding Window on Kelly Dev</title><link>https://kelly-chui.github.io/tags/sliding-window/</link><description>Recent content in Sliding Window on Kelly Dev</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 22 Jul 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://kelly-chui.github.io/tags/sliding-window/index.xml" rel="self" type="application/rss+xml"/><item><title>Programmers. 징검다리 건너기</title><link>https://kelly-chui.github.io/ps/2025/ps-programmers-crossing-stepping-stones/</link><pubDate>Tue, 22 Jul 2025 00:00:00 +0000</pubDate><guid>https://kelly-chui.github.io/ps/2025/ps-programmers-crossing-stepping-stones/</guid><description>&lt;h2 id="문제"&gt;문제&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://school.programmers.co.kr/learn/courses/30/lessons/64062"&gt;https://school.programmers.co.kr/learn/courses/30/lessons/64062&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="풀이"&gt;풀이&lt;/h2&gt;
&lt;p&gt;처음 문제를 읽어보고 바이너리 서치를 이용해야겠다고 생각했다. 결정해야 할 값을 건널 수 있는 최대 인원수로 맞춰놓고 바이너리 서치를 이용하여 찾으면 되기 때문이다.&lt;/p&gt;
&lt;p&gt;바이너리 서치를 이용한 알고리즘은 다음과 같다.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;바이너리 서치를 통해 찾고 싶은 값은 징검다리를 건널 수 있는 최대 인원 수이다.&lt;/li&gt;
&lt;li&gt;징검다리 하나의 내구도가 최대 2억이므로 1에서 2억까지의 범위 내에서 인원 수의 최대값을 찾는다
&lt;ol&gt;
&lt;li&gt;값이 유효한지 체크하는 방법은 징검다리에서 현재 인원 수가 밟은 수를 뺀 다음 0 이하의 징검다리 돌들이 연속되는 경우가 &lt;code&gt;k&lt;/code&gt;개 이하면 통과, 초과면 통과시키지 않는다.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;바이너리 서치 결과를 리턴한다.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;이 코드의 시간 복잡도는 $N$이 &lt;code&gt;stones&lt;/code&gt; 배열의 크기, $M$이 돌 내구도의 최대값이라 했을 때 $O(N \log M)$이다. 돌 내구도의 최대값은 2억이고, 2의 30제곱이 약 10억이므로 30번 이내에 찾을 수 있다. 최대 20만 크기의 배열을 30번 정도 반복한다고 생각하면 충분히 시간 복잡도가 나온다.&lt;/p&gt;</description></item></channel></rss>