Design Gurus Logo
Number of Flowers in Full Bloom (hard)

Problem Statement

You are given a 2D integer array flowers, where flowers[i] = [start<sub>i</sub>, end<sub>i</sub>] means the i<sup>th<sup> flower will be in full bloom from time start<sub>i</sub> to end<sub>i</sub> (inclusive). You are also given another 1D array persons, where persons[i] represents the time when i<sup>th<sup> person will come to see the flowers.

Return an integer array answer of size n, where answer[i] is the number of flowers that are in full bloom at the i<sup>th<sup> time.

Examples

Example 1:

  • Input: flowers = [[1,4],[2,2]], persons = [2,3]
  • Expected Output: [2,1]
  • Explanation: At time 2, both flowers are in full bloom. By time 3, the first flower is still in bloom, but the second one has wilted, leaving only one in bloom.

Example 2:

  • Input: flowers = [[5,10],[15,25],[25,30]], persons = [5,10,15,20,25,30]
  • Expected Output: [1,1,1,1,2,1]
  • Explanation: At time 5 and 10, only the first flower is in bloom. At time 15 and 25, only the second flower is in bloom. At time 25, second and third flowers are in bloom, and at time 30 only third flower is in bloom.

Example 3:

  • Input: flowers = [[1,50],[10,14],[6,10]], persons = [11,6,3]
  • Expected Output: [2,2,1]
  • Explanation: At time 11, the first and second flowers are in bloom. At time 6, the first and third flowers are in bloom. At time 3, only first flower is in bloom.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory