Data Structures & AlgorithmsHardCodeforces Div2 B · counting
Problem: How many ordered pairs (x, y) with 1 <= x, y <= 10 have x y <= 10? Run the code.
Problem: How many ordered pairs (x, y) with 1 <= x, y <= 10 have x * y <= 10? Run the code.
print(sum(1 for x in range(1, 11) for y in range(1, 11) if x * y <= 10))What is printed?
- A. 25
- B. 30
- C. 24
- D. 27
Correct answer: D. 27
For each x the count is floor(10 / x), giving 10 + 5 + 3 + 2 + 2 + 1 + 1 + 1 + 1 + 1 = 27.
More Coding Interview Problems questions
- Problem: How many integers in [1, 1000] contain the digit 0? Run the code. python print(sum(1 for x in range(1, 1001) if '0' in str(x)))…
- Problem: What is the minimum number of perfect squares (1, 4, 9, ...) that sum to 12? Run the DP. python INF = 10 9 dp = [0] + [INF] 12…
- Problem: How many non-decreasing strings of length 3 over the digits {0, 1, 2} exist? Run the code. python from itertools import product…
- 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?