Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice
Problem: What is the sum of the first 50 terms of the sequence 1, 1, 2, 3, 5, ... (Fibonacci numbers F(1) to F(50), with F(1)=F(2)=1)? Run the code.
Problem: What is the sum of the first 50 terms of the sequence 1, 1, 2, 3, 5, ... (Fibonacci numbers F(1) to F(50), with F(1)=F(2)=1)? Run the code.
a, b = 1, 1
total = 1 + 1
for _ in range(48):
a, b = b, a + b
total += b
print(total % 1000)What is printed?- A. 99
- B. 98
- C. 25
- D. 73
Correct answer: B. 98
Σ F(1..50) = F(52) − 1, and F(52) ends in …099, so the output is 98. Forgetting the − 1 gives 99, F(50) mod 1000 gives 25, and summing only 49 terms gives 73.
More Coding Interview Problems questions
- Problem: How many pairs (i < j) of [2, 4, 6, 9, 12, 15] have gcd(ai, aj) = 3? Run the code. python from math import gcd a = [2, 4, 6, 9…
- Problem: How many integers in [1, 300] are divisible by exactly two of the numbers 2, 3 and 5? Run the code. python print(sum(1 for x in…
- Problem: What is the minimum number of perfect cubes (1, 8, 27, ...) that sum to 100? Run the DP. python INF = 10 9 dp = [0] + [INF] 100…
- Problem: How many integers in [1, 200] have an even number of 1-bits in their binary form? Run the code. python print(sum(1 for x in…
- Problem: What is the length of the longest subarray of [1, 1, 0, 1, 1, 1, 0, 1] containing at most one zero? Run the sliding-window code…
- Problem: How many distinct products a b arise when a and b are each a face value from 1 to 6? Run the code. python print(len({a b for a in…