File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Time: O(n)
2
2
# Space: O(n)
3
3
4
+ # There is a garden with N slots. In each slot, there is a flower.
5
+ # The N flowers will bloom one by one in N days. In each day,
6
+ # there will be exactly one flower blooming and it will be in the status of blooming since then.
7
+ #
8
+ # Given an array flowers consists of number from 1 to N.
9
+ # Each number in the array represents the place where the flower will open in that day.
10
+ #
11
+ # For example, flowers[i] = x means that the unique flower that blooms at day i
12
+ # will be at position x, where i and x will be in the range from 1 to N.
13
+ #
14
+ # Also given an integer k, you need to output in which day there exists two flowers
15
+ # in the status of blooming, and also the number of flowers between them is k and
16
+ # these flowers are not blooming.
17
+ #
18
+ # If there isn't such day, output -1.
19
+ #
20
+ # Example 1:
21
+ # Input:
22
+ # flowers: [1,3,2]
23
+ # k: 1
24
+ # Output: 2
25
+ # Explanation: In the second day, the first and the third flower have become blooming.
26
+ #
27
+ # Example 2:
28
+ # Input:
29
+ # flowers: [1,2,3]
30
+ # k: 1
31
+ # Output: -1
32
+ # Note:
33
+ # The given array will be in the range [1, 20000].
34
+
4
35
class Solution (object ):
5
36
def kEmptySlots (self , flowers , k ):
6
37
"""
You can’t perform that action at this time.
0 commit comments