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.)
- A. 4
- B. 6
- C. 2
- 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.
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
- What is the sum of Hamming distances (number of differing bit positions) over all unordered pairs of [1, 3, 5, 7]?
- In [12, 4, 12, 4, 12, 4, 9] every value appears three times except one value that appears once. Which value appears once?
- What is the maximum value of a[i] XOR a[j] over index pairs i < j in [3, 10, 5, 25, 2, 8]?
- How many index pairs i < j in [6, 1, 8, 7, 3, 4] have a[i] AND a[j] = 0?
- How many times does the pattern "ababa" occur in the text "ababcababa", counting overlapping occurrences?
- How many palindromic substrings (counting each occurrence by position, length 1 and up included) does "abacaba" contain?