Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

Choose the fewest intervals of length 3 (covering integer points s, s+1, s+2 for a start s from 1 to 8) so that every integer point from 1 to 10 is covered. What is the minimum number of intervals?

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

Correct answer: D. 4

Greedy: place each interval as far right as possible while still covering the leftmost uncovered point. Ten points need at least ceil(10 / 3) = 4 intervals, and four suffice.

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

Exams that ask this topic