Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B

How many pairs of positions (i, j) with j − i ≥ 3 satisfy a[i] = a[j], for the array [1, 2, 1, 3, 2, 1, 3, 1]?

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

Correct answer: A. 6

Process positions left to right and add the counts of each value seen at least k positions earlier (delayed insertion into a frequency map). Counting all equal pairs ignores the distance condition.

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

Exams that ask this topic