Data Structures & AlgorithmsModerateTCS NQT · Product Company OA
Problem: How many integers in [1, 30] are even but not divisible by 4? Run the code.
Problem: How many integers in [1, 30] are even but not divisible by 4? Run the code.
print(sum(1 for x in range(1, 31) if x % 2 == 0 and x % 4 != 0))What is printed?
- A. 7
- B. 15
- C. 8
- D. 9
Correct answer: C. 8
There are 15 even numbers and 7 multiples of 4 in [1, 30], so 8 remain.
More Coding Interview Problems questions
- Problem: What is the total length covered by the union of the intervals [1, 3], [2, 6] and [8, 10]? Run the code. python iv = sorted([(1…
- Problem: What does this Python snippet print? def add(x, bucket=[]): bucket.append(x) return len(bucket) add(1); add(2) print(add(3))
- Problem: What does this Python snippet print? g = [[0]3]3 g[1][2] = 7 print(sum(map(sum, g)))
- Problem: What does this Python snippet print? print(-7 // 2, -7 % 3, 7 // -2)
- Problem: What does this snippet print? gen = (xx for x in range(4)) print(sum(gen), sum(gen))
- Problem: What does this snippet print? fs=[lambda: i for i in range(3)] print([f() for f in fs])