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}))
  1. A. 4
  2. B. 2
  3. C. 5
  4. 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

Exams that ask this topic