Data Structures & AlgorithmsModerateTCS NQT · number theory
Problem: How many integers in [1, 999] are divisible by 7 but not by 14? Run the code.
Problem: How many integers in [1, 999] are divisible by 7 but not by 14? Run the code.
print(sum(1 for x in range(1, 1000) if x % 7 == 0 and x % 14 != 0))What is printed?
- A. 71
- B. 142
- C. 72
- D. 70
Correct answer: A. 71
There are 142 multiples of 7 and 71 multiples of 14 below 1000, so 142 - 71 = 71 remain. Including the multiples of 14 gives the trap 142.
More Coding Interview Problems questions
- Problem: How many ordered pairs (i < j) of [1, 2, 3, 4, 6] have a[j] divisible by a[i]? Run the code. python a = [1, 2, 3, 4, 6]…
- Problem: What is the minimum number of operations to go from 1 to 10 when each operation is +1 or 2? Run the BFS. python from collections…
- Problem: How many binary strings of length 4 avoid the substring '11'? Run the code. python print(sum(1 for t in range(16) if '11' not in…
- Problem: What is the minimum number of insertions and deletions needed to turn 'abc' into 'adc'? (Only insertions and deletions are…
- Problem: What is the longest common prefix of the list ['flower', 'flow', 'flight']? Run the code. python import os…
- Problem: What does the following print? python print(' '.join('the sky is blue'.split()[::-1]))