Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

Flowers bloom on the days [1, 10, 3, 10, 2]. You need to make 2 bouquets, each from 2 adjacent bloomed flowers (flowers may only be used once). What is the minimum day on which this is possible?

  1. A. 10
  2. B. 11
  3. C. 9
  4. D. 3

Correct answer: A. 10

Binary search on the day with a linear feasibility check that counts adjacent bloomed runs of length k, resetting the run after each bouquet. Before day 10 the bloomed flowers sit at positions 0, 2 and 4, which are never adjacent; at day 10 the pairs (0,1) and (2,3) both bloom.

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

Exams that ask this topic