Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
How many index pairs i < j in [4, 9, 1, 7, 3, 8, 2] have a sum s with 6 <= s <= 10?
- A. 11
- B. 9
- C. 8
- D. 7
Correct answer: C. 8
Sort, then count pairs with sum at most R minus pairs with sum at most L-1 using two pointers; this avoids the index-order bookkeeping. The bounds are inclusive on both ends.
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 [10, 5, 2, 6] have a product strictly less than 100?
- Greedy removal: scanning "aabaacaab" left to right, you delete any 'a' that immediately follows another 'a' in the current output. How…
- Remove exactly 2 digits from "7419" (keeping order) to make the largest possible number. What is the result?
- Using the Z-function on "ab#abababcab", how many occurrences of the pattern "ab" are found in the text "abababcab"?
- For "abacabad", how many indices i (0-indexed) have prefix-function value pi[i] equal to 0?
- For the string "abcdeca", take all length-2 substrings and hash each with h(xy) = (ord(x) + 2ord(y)) mod 5. How many index pairs i < j of…