Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integer solutions (a, b) with 1 <= a <= b <= 20 satisfy a b = 36? Run the code.
Problem: How many integer solutions (a, b) with 1 <= a <= b <= 20 satisfy a * b = 36? Run the code.
print(sum(1 for a in range(1, 21) for b in range(a, 21) if a * b == 36))What is printed?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
The factor pairs of 36 with a <= b and b <= 20 are (1,36) excluded by the bound, (2,18), (3,12), (4,9), (6,6).
More Coding Interview Problems questions
- Problem: What is the length of the longest common subsequence of 'abcdef' and 'acebdf'? Run the DP. python a, b = 'abcdef', 'acebdf' dp =…
- Problem: What is the number of subsets of {1, 2, ..., 8} whose elements sum to a multiple of 8? Run the code. python print(sum(1 for m in…
- Problem: How many pairs (i < j) of [1, 4, 9, 16, 25] have a[j] - a[i] divisible by 3? Run the code. python a = [1, 4, 9, 16, 25]…
- Problem: What is the number of set bits in 2^30 - 1? Run the code. python print(bin(2 30 - 1).count('1')) What is printed?
- Problem: How many integers in [1, 300] are multiples of 6 but not of 9? Run the code. python print(sum(1 for x in range(1, 301) if x % 6…
- Problem: How many ordered triples (a, b, c) of positive integers satisfy a + b + c = 7? Run the code. python print(sum(1 for a in range(1…