Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the maximum value of a[i] + a[j] over pairs with j - i >= 2 in [5, 1, 8, 2, 9, 3]?
- A. 18
- B. 17
- C. 14
- D. 12
Correct answer: B. 17
Keep the prefix maximum of a[0..j−2] and add a[j]: 8 (index 2) + 9 (index 4) = 17. Pairing 9 with itself gives 18, demanding a gap of 3 gives 14, and 12 is 9 plus its adjacent neighbour 3.
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 minimum number of elements that must be deleted from [4, 4, 1, 1, 1, 2, 3, 3] so the remaining values are pairwise distinct?
- How many index pairs i < j in [1, 2, 3, 4, 7, 8] have a[i] XOR a[j] equal to a power of two (1, 2, 4, 8, ...)?
- How many positive divisors does the product 4 6 9 have?
- Which minimum number of intervals from [(0,2),(1,4),(3,6),(5,9),(7,10)] are needed to cover the segment [0, 10] completely (the union must…
- What is the length of the longest contiguous subarray of [2, 4, 1, 3, 6, 7, 8, 5, 9] containing at most two odd numbers?
- For windows of size 2 over [4, 2, 12, 11, 5] (using 5 in place of -5), what is the largest window minimum?