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}))
- A. [2, 3] True 2
- B. [2, 3] True 3
- C. [1, 2, 3] True 2
- 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
- Problem: The number 1000000007 is used as a modulus in competitive programming. How many times does the decimal digit 7 appear in the…
- Problem: In a bit-trick loop, n = 0b101101 is processed by repeatedly computing n &= n − 1 until n becomes 0. How many iterations are…
- Problem: The XOR of the values 1 through 10 is XOR-ed with the XOR of the values 1 through 9. What is the resulting value?
- Problem: The list [5, 8, 1, 9, 3, 7, 2] is split into two halves (the first ⌈n/2⌉ elements and the rest). Each half is sorted, and the two…
- Problem: Compute the sum of the integers from 1 to 1000 that are divisible by 7 or by 11 but not by 77.
- Problem: How many distinct values does the expression (i j) mod 7 take as i and j range independently over 1 ≤ i, j ≤ 7?