Data Structures & AlgorithmsVery hardTCS NQT · Infosys
How many unordered index pairs i < j in the sorted array [1, 3, 4, 6, 8, 9, 11] satisfy a[i] + a[j] = 12?
- A. 3
- B. 4
- C. 5
- D. 7
Correct answer: A. 3
The pairs summing to 12 are (1, 11), (3, 9), (4, 8). The two-pointer scan finds each in one pass.
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 non-empty substrings does the string aaaa have?
- An array has only positive integers and you need the longest contiguous subarray whose sum is at most K, with n up to 10^6. Which method…
- How many contiguous subarrays of [3, 1, 4, 1, 5, 9] have a prime sum?
- What is the minimum number of elements to delete from [4, 7, 2, 9, 5] so that the remaining sum is divisible by 3? (The empty remainder is…
- How many index pairs i < j of [1, 2, 4, 6, 7, 9] have a sum strictly between 5 and 10?
- How many index pairs i < j in [2, 5, 3, 4, 1] satisfy a[i] < a[j] and every element strictly between i and j is at most a[j]?