Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture

Problem: What is the output? print(sorted({3,1,2} & {2,3,4}), 3 in {1,2,3}, len({1,1,2}))

  1. A. [2, 3] True 2
  2. B. [2, 3] True 3
  3. C. [1, 2, 3] True 2
  4. D. [2, 3] False 2

Correct answer: A. [2, 3] True 2

The intersection is {2, 3}, membership is True, and duplicates collapse in a set, leaving two elements. A list-based reading of the set literal would count the duplicate.

More Coding Interview Problems questions

Exams that ask this topic