Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many DISTINCT values v exist such that both v and v + 3 appear in [1, 5, 3, 4, 2, 4, 6, 1]? (Count distinct pair values, not index pairs.)

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

Correct answer: D. 3

Use a set: for each value v check whether v + 3 is present, counting each v once. Counting index pairs with duplicates gives a larger number because 4 and 1 repeat.

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

Exams that ask this topic