Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Four sets {1,2,3}, {2,4}, {3,4,5}, {1,5} are given. How many non-empty sub-collections of these sets have a union equal to {1, 2, 3, 4, 5}?
- A. 8
- B. 6
- C. 5
- D. 9
Correct answer: B. 6
Enumerate the 15 non-empty sub-collections and test each union; the count is over sub-collections, not over elements. Counting minimal covers alone gives a smaller number, which is the common confusion.
More Coding Interview Problems questions
- Problem: How many pairs of equal values (i < j, a[i] = a[j]) does a = [1, 2, 1, 3, 2, 2] contain? Run the code. python from collections…
- Problem: How many longest increasing subsequences does [1, 3, 5, 4, 7] have? Run the DP that counts both length and number of optimal…
- Problem: What is the largest number of distinct characters in any window of length 3 of 'abcabc'? Run the code. python s = 'abcabc'…
- Problem: How many distinct values does x XOR y take over pairs of distinct elements of [1, 2, 3]? Run the code. python from itertools…
- Problem: What does the following print? It sums the entries at even positions of the array sorted in descending order. python a = [5, 1…
- Problem: What is the maximum sum of non-adjacent elements of [3, 2, 7, 10]? Run the DP. python a = [3, 2, 7, 10] inc = exc = 0 for x in a…