Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: Compute the sum of the integers from 1 to 1000 that are divisible by 7 or by 11 but not by 77.
- A. 110110
- B. 104104
- C. 116116
- D. 98098
Correct answer: B. 104104
Multiples of 7 sum to 71071 and of 11 to 45045; the multiples of 77 (sum 6006) are counted in both and must be removed entirely: 71071 + 45045 − 2·6006 = 104104. Removing them once gives 110110, not removing them gives 116116, and removing them three times gives 98098.
More Coding Interview Problems questions
- Problem: How many distinct values does the expression (i j) mod 7 take as i and j range independently over 1 ≤ i, j ≤ 7?
- Problem: What does the following print? python x = [[0] 2] 2 x[0][1] = 5 print(x)
- Problem: What does the following print? python print(0.1 + 0.2 == 0.3, round(2.5), round(3.5))
- Problem: What does the following print? python a = [1, 2, 3] b = a b += [4] print(a)
- Problem: What does the following print? python print(int('0b101', 0), int('101', 2), 7 // 2 2)
- Problem: What does the following print? python fs = [lambda: i for i in range(3)] print([f() for f in fs])