Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B
In the array [2, 8, 5, 5, 3, 7, 5], how many index pairs i < j have a[i] + a[j] = 10?
- A. 5
- B. 6
- C. 7
- D. 9
Correct answer: A. 5
Pairs are 2 with 8, 3 with 7, and every pair of the three 5s (which give 3 pairs). Counting only distinct values misses the repeated 5s.
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 distinct sums are obtained by contiguous non-empty subarrays of [1, -1, 2, -2]?
- What is the length of the longest substring of aabbcaabcc in which every character occurs at least twice?
- How many palindromic substrings of length at least 2 does abcbaccab contain (counted by position)?
- How many distinct substrings of length 3 of abcabcabc occur at least twice in the string?
- How many ways can the digit string 226 be decoded when 1 to 26 map to A to Z?
- What is the length of the longest substring of banana that appears at least twice in the string (occurrences may overlap)?