Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the maximum value of x (100 - x) over integers 0 <= x <= 100? Run the code.

Problem: What is the maximum value of x * (100 - x) over integers 0 <= x <= 100? Run the code.
print(max(x * (100 - x) for x in range(0, 101)))
What is printed?
  1. A. 2499
  2. B. 5000
  3. C. 10000
  4. D. 2500

Correct answer: D. 2500

x(100 − x) peaks at x = 50, giving 2500. Skipping 50 (49 · 51) gives 2499, 100²/2 gives 5000, and 100 · 100 gives 10000.

More Coding Interview Problems questions

Exams that ask this topic