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]?
- A. 6
- B. 8
- C. 3
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many non-empty contiguous subarrays of [2, 2, 5, -1, 3, 4, 1] have a sum that is a perfect square (0 counts as a square)?
- How many non-empty subsets of [3, 1, 4, 2, 5] (chosen by position) have a sum between 4 and 7 inclusive?
- Choose a subsequence of length exactly 3 from [5, 1, 4, 2, 6, 3, 7, 2] (keeping order) whose elements are non-decreasing. What is the…
- How many DIFFERENT palindromic strings of length 3 occur as subsequences of "abcbaab" (each string counted once, however many index…
- Deleting exactly one character from "110100" gives a new binary string each time. How many DISTINCT strings result?
- How many DISTINCT palindromic strings (of any length ≥ 1) occur as subsequences of "abab"?