Skip to content

Commit f040213

Browse files
authored
Update k-empty-slots.py
1 parent 115eeb7 commit f040213

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Python/k-empty-slots.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
# Time: O(n)
22
# Space: O(n)
33

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+
435
class Solution(object):
536
def kEmptySlots(self, flowers, k):
637
"""

0 commit comments

Comments
 (0)