Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B
In [3, 8, 1, 6, 9, 4], find the pair of distinct indices (i < j) with a[i] + a[j] = 10, minimising i + j. What is the minimum value of i + j?
- A. 8
- B. 6
- C. 2
- D. 10
Correct answer: B. 6
With a hash map of earlier values, pairs summing to 10 are (indices 2, 4: 1 + 9) and (3, 5: 6 + 4), so the minimum index sum is 6. The other pair gives 8, as does using 1-based indices; 2 reports i alone and 10 is the target.
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 appear among the windows of exactly 3 consecutive elements of [4, 1, 4, 2, 1, 4, 2]?
- How many contiguous subarrays of 4 2 6 2 5 3 2 7 contain EXACTLY one occurrence of the global minimum value 2?
- Add up the LENGTHS of all contiguous subarrays of 1 3 2 2 5 4 6 that are non-decreasing (each qualifying subarray contributes its length…
- How many contiguous subarrays of 5 2 7 3 9 4 1 of length at least 2 have pairwise DISTINCT values, and whose FIRST element is their maximum?
- What is the maximum sum of a contiguous subarray of 4 9 1 6 3 2 8 5 that has length at least 2 and whose sum is divisible by 5?
- What is the length of the shortest contiguous subarray of 3 8 1 5 8 2 3 7 whose two END elements are equal?