This question is a variant of k empty slot from leetcode. the new question is, ask to find the last day when there are k consecutive bloomed flowers.
e.g. total 7 days, 1 represents flower bloomed,0 represents flower not bloomed, k=3
day1:1 0 0 0 0 0 0
day2:1 0 1 0 0 0 0
day3:1 1 1 0 0 0 0 1st time find k consecutive bloomed flowers
update: lastDayBloomKflowers = 3
day4:1 1 1 0 1 0 0
day5:1 1 1 0 1 1 0
day6:1 1 1 0 1 1 1 2nd time find k consecutive boomed flowers
update: lastDayBloomKflowers = 6
day7:1 1 1 1 1 1 1
finally, flowers will bloom at all position
so the final solution is lastDayBloomKflowers = 6
how can we get lastDayBloomKflowers
?
the time complexity is O(nlogn)
, space is O(n)
I know how to solve the original leetcode question, I would like to use tree set, but for this variant, I have no idea what data-structure I should use, and efficiently solve it.
Thank you for your time!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I am asking for help for the variant of k empty slot problem.
Since the url for k empty slot problem on leetcode is for prime number, and some of you guys may not able to open, I will show you original k empty slot problem here:
There is a garden with N slots. In each slot, there is a flower. The N flowers will bloom one by one in N days. In each day, there will be exactly one flower blooming and it will be in the status of blooming since then.
Given an array flowers consists of number from 1 to N. Each number in the array represents the place where the flower will open in that day.
For example, flowers[i] = x means that the unique flower that blooms at day i will be at position x, where i and x will be in the range from 1 to N.
Also given an integer k, you need to output in which day there exists two flowers in the status of blooming, and also the number of flowers between them is k and these flowers are not blooming.