Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many distinct values v occur in [5, 1, 2, 3, 9, 10, 4] such that v + 1 also occurs in the array?

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

Correct answer: D. 5

Put the values in a set and test each v for v + 1 membership. The values 1, 2, 3, 4 (successors up to 5) and 9 (successor 10) give five.

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

Exams that ask this topic