Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional

Group the values [1, 2, 4, 5, 6, 9, 10] so that consecutive sorted values with difference at most 1 share a group. How many groups result?

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

Correct answer: A. 3

After sorting, a new group starts whenever the gap exceeds 1. The gaps 2 to 4, 6 to 9 are the breaks, so there are three groups.

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

Exams that ask this topic