Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT
The array [1, 9, 4, 6, 2, 8] has even length. You pair up the elements (each element in exactly one pair), and the cost of the arrangement is the largest pair sum. What is the minimum possible largest pair sum?
- A. 17
- B. 3
- C. 30
- D. 10
Correct answer: D. 10
Sort to 1, 2, 4, 6, 8, 9 and pair smallest with largest: 1+9, 2+8, 4+6 all equal 10, matching the lower bound 30/3 = 10. Pairing sorted neighbours gives 8 + 9 = 17, 3 is the minimum pair sum, and 30 is the total.
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 contiguous subarrays of [2, 5, 1, 5, 3, 4, 5] have a maximum element exactly equal to 5?
- 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 +…
- 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?