Data Structures & AlgorithmsModerateTCS NQT · basics

Problem: What is the product of the distinct elements of [2, 2, 3, 4, 4]? Run the code.

Problem: What is the product of the distinct elements of [2, 2, 3, 4, 4]? Run the code.
a = [2, 2, 3, 4, 4]
p = 1
for x in set(a):
    p *= x
print(p)
What is printed?
  1. A. 24
  2. B. 96
  3. C. 48
  4. D. 12

Correct answer: A. 24

The distinct values are 2, 3 and 4, with product 24. Using the full list gives 2 * 2 * 3 * 4 * 4 = 192, a different value.

More Coding Interview Problems questions

Exams that ask this topic