As reported: Cohesity MTS-3, June 2025, round 1 (DSA). The round went from a brute force to a sweep-line solution and then to an optimized one.
This is LeetCode 2251 — Number of Flowers in Full Bloom. Our write-up: /number-of-flowers-in-full-bloom.
You are given a 0-indexed 2D integer array flowers, where flowers[i] = [start_i, end_i] means flower i is in full bloom from day start_i to day end_i (inclusive). You are also given an array people, where people[i] is the day person i arrives to see the flowers.
Return an array answer of length people.length, where answer[i] is the number of flowers in full bloom when person i arrives.
Example 1
flowers = [[1,6],[3,7],[9,12],[4,13]], people = [2,3,7,11]
Output: [1,2,2,2]
Example 2
flowers = [[1,10],[3,3]], people = [3,3,2]
Output: [2,2,1]
Constraints: 1 <= flowers.length <= 5 * 10^4, 1 <= start_i <= end_i <= 10^9, 1 <= people.length <= 5 * 10^4, 1 <= people[i] <= 10^9.
Code runner format: one JSON value per line: flowers, people. Implement fullBloomFlowers(flowers, people) returning the array of counts.