Leetcode Problem 2251. Number of Flowers in Full Bloom

2251. Number of Flowers in Full Bloom

Leetcode Solutions

Approach: Simpler Binary Search

  1. Create two arrays starts and ends.
  2. Iterate over each flower = [start, end] in flowers:
    • Add start to starts.
    • Add end + 1 to ends.
  3. Sort both starts and ends.
  4. Initialize the answer array ans and iterate over each person in people:
    • Perform a binary search on starts for the rightmost insertion index of person to find i.
    • Perform a binary search on ends for the rightmost insertion index of person to find j.
    • Add i - j to ans.
  5. Return ans.
UML Thumbnail

Approach: Heap/Priority Queue

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...