Number of Flowers in Full Bloom

Hard Topics Company Tags

Each flower blooms over an inclusive time interval. flowers[i] = [start, end] means that flower is blooming at every time from start through end, including both endpoints.

people[j] is the arrival time of person j. Return an array whose entry at index j counts the flowers blooming at that person's arrival. Preserve the order of people in the answer.

Flowers may have identical intervals, and people may arrive at the same time. Each flower is counted separately.

Example 1:

Number of Flowers in Full Bloom, example 1: illustration of the example

Input: flowers = [[2,4],[4,6],[7,7]]
people = [1,4,6,7]

Output: [0,2,1,1]

Explanation: At time 1 no flower is blooming. At time 4, both [2,4] and [4,6] count because endpoints are included. Times 6 and 7 each have one blooming flower.

Example 2:

Number of Flowers in Full Bloom, example 2: illustration of the example

Input: flowers = [[3,8],[3,8],[5,5]]
people = [5,3,9,5]

Output: [3,2,0,3]

Explanation: The two identical [3,8] intervals count as separate flowers. At time 5 all three flowers bloom; at time 3 only the first two do; at time 9 none do. Repeated time 5 gives the same count again.

Example 3:

Number of Flowers in Full Bloom, example 3: illustration of the example

Input: flowers = [[10,12]]
people = [12,10,11,13]

Output: [1,1,1,0]

Explanation: The flower is blooming at times 10, 11, and 12, including both endpoints. It has stopped by time 13. Answers follow the given arrival order.

Constraints:

  • 1 <= flowers.length <= 50000
  • flowers[i].length == 2
  • 1 <= flowers[i][0] <= flowers[i][1] <= 1000000000
  • 1 <= people.length <= 50000
  • 1 <= people[i] <= 1000000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.