Data Structures & AlgorithmsHardProduct Company SDE · sorting OA
Problem: What is the maximum product of three numbers in [-10, -10, 5, 2]? Run the code.
Problem: What is the maximum product of three numbers in [-10, -10, 5, 2]? Run the code.
a = sorted([-10, -10, 5, 2]) print(max(a[-1] * a[-2] * a[-3], a[0] * a[1] * a[-1]))What is printed?
- A. 100
- B. -90
- C. 500
- D. 20
Correct answer: C. 500
The three largest values give 5 * 2 * (-10) = -100, while the two most negative numbers times the largest give (-10) * (-10) * 5 = 500.
More Coding Interview Problems questions
- Problem: What is the maximum subarray sum over all prefixes of [-2, 1, -3, 4]? Print the list of running maximum-subarray values with…
- Array a = [1, -2, 3, 2, -1, 4, -3, 2]. What is the length of the longest contiguous subarray whose sum is exactly 4?
- Array a = [3, -5, 2, -1, -4, 2, 1, -6, 2]. How many contiguous subarrays of length exactly 4 have a negative sum?
- Sorted array [1, 2, 2, 3, 5, 5, 6, 8]. How many index pairs i < j have 6 <= a[i] + a[j] <= 8?
- How many non-empty subsets of {1, 2, 3, 4, 5, 6, 7} have a bitwise AND of their elements equal to 0?
- Lists L1 = {1, 4, 7}, L2 = {2, 5, 8} and L3 = {3, 6, 9}. Choosing one element from each list, how many choices give a total of 15?