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?
- A. 2499
- B. 5000
- C. 10000
- 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
- Problem: What is the number of trailing zeros in 100! expressed in base 6 (count of factors of 6)? Run the code. python n = 100 c2 = c3 =…
- Problem: How many ways can you pick 2 different integers from [1, 20] whose sum is divisible by 4? Run the code. python print(sum(1 for i…
- Problem: What is the count of 3-digit numbers whose digits are all distinct and in strictly increasing order? Run the code. python…
- Problem: What is the sum of the first 100 positive integers that are not divisible by 3? Run the code. python print(sum(x for x in…
- Problem: How many distinct values does x mod 12 take over the numbers x in [1, 1000] that are not divisible by 4? Run the code. python…
- Problem: What is the length of the longest palindromic substring of 'abacdcaba'? Run the code. python s = 'abacdcaba' best = 0 for c in…