Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the maximum product of 4 consecutive elements of [1, 2, 3, 4, 5, 6]? Run the code.

Problem: What is the maximum product of 4 consecutive elements of [1, 2, 3, 4, 5, 6]? Run the code.
a = [1, 2, 3, 4, 5, 6]
print(max(a[i] * a[i + 1] * a[i + 2] * a[i + 3] for i in range(len(a) - 3)))
What is printed?
  1. A. 24
  2. B. 720
  3. C. 360
  4. D. 120

Correct answer: C. 360

The windows give 24, 120, 360, so 3·4·5·6 = 360 is the maximum. 24 is the first window, 120 the middle one, and 720 the product of all six.

More Coding Interview Problems questions

Exams that ask this topic