Let days = i be the time that the flower at position x blooms. įor each contiguous block ("window") of k positions in the flower bed, we know it satisfies the condition in the problem statement if the minimum blooming date of this window is larger than the blooming date of the left and right neighbors.īecause these windows overlap, we can calculate these minimum queries more efficiently using a sliding window structure. Time Complexity (Java):, where is the length of flowers. If some neighbor satisfies the condition, we know the condition occurred first on this day. When we add a flower to active, we should check it's lower and higher neighbors. We'll maintain active, a sorted data structure containing every flower that has currently bloomed. When each flower blooms, we check it's neighbors to see if they can satisfy the condition with the current flower. Let's add flowers in the order they bloom. Approach #1: Insert Into Sorted Structure
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |