Data Structures & AlgorithmsModerateTCS NQT Digital · Python semantics
Problem: What does the following print?
Problem: What does the following print?
print(len({1, 2, 3} & {2, 3, 4} | {5}))- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
The & operator binds tighter than |, so the expression is ({2, 3}) | {5} = {2, 3, 5}, of size 3.
More Coding Interview Problems questions
- Problem: What does the following print? python print('10' < '9', 10 < 9)
- Problem: What does the following print? python print(int('12', 8) + int('0x1f', 16))
- Problem: How many strings of length 4 over {a, b} contain neither 'aa' nor 'bb' as a substring? Run the code. python from itertools import…
- Problem: What is the sum of Euler's totient phi(k) for k = 1 to 20? Run the code. python from math import gcd print(sum(sum(1 for g in…
- Problem: How many integers in [1, 100] have exactly 4 positive divisors? Run the code. python print(sum(1 for x in range(1, 101) if sum(1…
- Problem: What is the maximum number of pairwise non-overlapping non-empty subarrays of [1, -1, 2, -2, 3, -3] each having sum zero? Run the…