Data Structures & AlgorithmsHardICPC regional · combinatorics
Problem: How many non-decreasing strings of length 3 over the digits {0, 1, 2} exist? Run the code.
Problem: How many non-decreasing strings of length 3 over the digits {0, 1, 2} exist? Run the code.
from itertools import product print(sum(1 for t in product(range(3), repeat=3) if all(t[i] <= t[i + 1] for i in range(2))))What is printed?
- A. 9
- B. 12
- C. 10
- D. 27
Correct answer: C. 10
The count is C(3 + 3 - 1, 3) = C(5, 3) = 10 by stars and bars.
More Coding Interview Problems questions
- Problem: What is the maximum sum of a strictly increasing subsequence of [1, 101, 2, 3, 100, 4, 5]? Run the DP. python a = [1, 101, 2, 3…
- Problem: How many unordered pairs of indices (i < j) of [5, 5, 5, 5] have a sum of 10? Run the code. python a = [5, 5, 5, 5] print(sum(1…
- Problem: What does the following print? python print(list(map(lambda x: x 2, filter(lambda x: x % 2, range(6))))) What is printed?
- Problem: What does the following print? python print(bool([]), bool([0]), bool(0.0), bool('False')) What is printed?
- Problem: What does the following print? python a = (1,) print(a 3, len(a 0)) What is printed?
- Problem: What does the following print? python print(list('abc')[::-1] == ['c', 'b', 'a'], 'abc'.index('c')) What is printed?