Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many index pairs i < j in [1, 4, 6, 9, 10, 12] satisfy a[i] + a[j] >= 15?
- A. 6
- B. 15
- C. 7
- D. 4
Correct answer: C. 7
On the sorted array each left index pairs with a suffix: (4,12), (6,9), (6,10), (6,12), (9,10), (9,12), (10,12) = 7. Using > 15 drops (6,9) and gives 6, 15 counts all pairs, and 4 counts only the pairs with 12.
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 subarrays [i..j] of [3, 1, 4, 1, 5] have their first element strictly greater than every other element of the subarray?
- What is the smallest positive integer x such that x(x+1)(x+2)/6 is at least 100?
- What is the maximum number of pairwise disjoint non-empty contiguous subarrays of [1, -1, 2, -2, 3, -3, 4] that each have sum zero?
- How many entries of [7, 8, 11, 16, 15, 3] have the largest number of 1-bits in the array?
- Sort all suffixes of "banana" lexicographically. What is the sum of the lengths of the longest common prefixes of each pair of adjacent…
- How many distinct substrings of length 4 does "abcabcabca" contain?