Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
Remove exactly one element from [5, -4, 3, -7, 2], then take the maximum product of two distinct remaining elements. What is that maximum product?
- A. 29
- B. 26
- C. 28
- D. 35
Correct answer: C. 28
Try each removal and take the best pair product of the remaining four values. Keeping the two largest positives without considering the negatives misses the pair (-7, -4) type candidates.
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 starting positions in "abcbabcab" match the pattern "abc" with exactly one mismatched character?
- How many substrings of length 2 of "abcba" read the same forwards and backwards?
- A histogram has bar heights [2, 1, 5, 6, 2, 3, 4, 1] (each bar has width 1). What is the area of the largest rectangle that fits entirely…
- What is the sum of the minimum element over every contiguous subarray of [3, 1, 2, 4, 1]? (Every subarray counts, including repeated…
- Sum the maximum of every contiguous window of length 3 in the array [1, 3, -1, -3, 5, 3, 6, 7] (there are n − k + 1 windows). What is the…
- The stock span on day i is the number of consecutive days up to and including day i with price ≤ the price on day i. Prices are [100, 80…