Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
How many index pairs i < j of [1, 2, 3, 4, 5, 6] have a product strictly less than 20?
- A. 13
- B. 15
- C. 12
- D. 9
Correct answer: C. 12
Two pointers on the sorted values count, for each left value, the right values keeping the product below 20: 5 (with 1) + 4 (with 2) + 3 (with 3) = 12. Allowing products equal to 20 (4 × 5) gives 13, 15 counts all pairs and 9 counts only the pairs that use 1 or 2.
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
- Evaluate the postfix expression "2 3 4 + 5 -".
- What is the length of the longest substring of "aabbaacc" in which every letter appears at most twice?
- What is the sum of the integers from 1 to 100 inclusive that are not perfect squares?
- Sum the largest power of two that divides each element of [12, 40, 7, 24]. What is the total?
- On a 3 by 3 grid, how many unordered pairs of distinct cells share a row or a column?
- What is the length of the longest run of equal consecutive values in [5, 5, 5, 6, 6, 5, 5, 5, 5]?