Data Structures & AlgorithmsHardLeetCode-style · TCS NQT

Flowers bloom on the days [1, 10, 3, 10, 2] (one flower per position). You need m = 3 bouquets, and each bouquet needs k = 1 adjacent bloomed flowers. What is the minimum day on which you can make 3 bouquets, or −1 if it is impossible?

  1. A. 4
  2. B. 3
  3. C. 10
  4. D. 5

Correct answer: B. 3

Binary search the day d: count how many disjoint runs of length k of flowers with bloom ≤ d you can take greedily, and check it reaches m. The feasibility test is monotone in d. Taking the day of the m-th earliest bloom is wrong when the flowers must be adjacent.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic