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?- A. 24
- B. 96
- C. 48
- 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
- Problem: What is the minimum absolute difference between two values of the sorted list [1, 5, 6, 9]? Run the code. python a = sorted([1…
- Problem: How many 2-element subsets of {1, 2, 3, 4, 5} have an even sum? Run the code. python from itertools import combinations…
- Problem: Which statement about the sparse table data structure for static range-minimum queries is correct?
- Problem: Which statement about heavy-light decomposition for path queries on a tree is correct?
- Problem: Which statement about Fermat's little theorem is correct?
- Problem: What is the time for one point update and one rectangle-sum query in a 2D Fenwick tree on an n x n grid?