|
| 1 | +<p>You have <code>n</code> bulbs in a row numbered from <code>1</code> to <code>n</code>. Initially, all the bulbs are turned off. We turn on <strong>exactly one</strong> bulb every day until all bulbs are on after <code>n</code> days.</p> |
| 2 | + |
| 3 | +<p>You are given an array <code>bulbs</code> of length <code>n</code> where <code>bulbs[i] = x</code> means that on the <code>(i+1)<sup>th</sup></code> day, we will turn on the bulb at position <code>x</code> where <code>i</code> is <strong>0-indexed</strong> and <code>x</code> is <strong>1-indexed.</strong></p> |
| 4 | + |
| 5 | +<p>Given an integer <code>k</code>, return <em>the <strong>minimum day number</strong> such that there exists two <strong>turned on</strong> bulbs that have <strong>exactly</strong> <code>k</code> bulbs between them that are <strong>all turned off</strong>. If there isn't such day, return <code>-1</code>.</em></p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> bulbs = [1,3,2], k = 1 |
| 12 | +<strong>Output:</strong> 2 |
| 13 | +<b>Explanation:</b> |
| 14 | +On the first day: bulbs[0] = 1, first bulb is turned on: [1,0,0] |
| 15 | +On the second day: bulbs[1] = 3, third bulb is turned on: [1,0,1] |
| 16 | +On the third day: bulbs[2] = 2, second bulb is turned on: [1,1,1] |
| 17 | +We return 2 because on the second day, there were two on bulbs with one off bulb between them.</pre> |
| 18 | + |
| 19 | +<p><strong class="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>Input:</strong> bulbs = [1,2,3], k = 1 |
| 23 | +<strong>Output:</strong> -1 |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p> </p> |
| 27 | +<p><strong>Constraints:</strong></p> |
| 28 | + |
| 29 | +<ul> |
| 30 | + <li><code>n == bulbs.length</code></li> |
| 31 | + <li><code>1 <= n <= 2 * 10<sup>4</sup></code></li> |
| 32 | + <li><code>1 <= bulbs[i] <= n</code></li> |
| 33 | + <li><code>bulbs</code> is a permutation of numbers from <code>1</code> to <code>n</code>.</li> |
| 34 | + <li><code>0 <= k <= 2 * 10<sup>4</sup></code></li> |
| 35 | +</ul> |
0 commit comments