Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B
How many index pairs (i < j) of the list [1, 3, 2, 3, 4, 5, 3, 1, 2, 5] satisfy a[i] + a[j] = 6? Equal values at different positions count as different pairs.
- A. 3
- B. 8
- C. 18
- D. 9
Correct answer: D. 9
Count with a frequency map: for each value v, add freq[v] × freq[T − v] (halving the self-pairs when v = T − v). Reporting distinct value-pairs merges repeats, and that is a different count from index pairs.
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 unordered pairs of distinct positions in [2, 3, 4, 6, 8, 9, 12] have a product divisible by 6?
- How many DISTINCT substrings of length exactly 3 does "abcabcbb" contain?
- How many substrings of "aeixoaeiuxoaeiou" consist only of vowels AND contain all five vowels a, e, i, o, u at least once?
- Consider the pattern-matching algorithms: naive, KMP, Rabin–Karp (polynomial rolling hash), Z-function. Which statement is correct?
- A polynomial rolling hash with a fixed modulus M and random base B is used to compare two different strings of length L. Which statement…
- What is the length of the longest palindromic substring of "bananaracecarbnn"?