Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integer triples (a, b, c) with 1 <= a <= b <= c <= 10 have a b c = 36? Run the code.
Problem: How many integer triples (a, b, c) with 1 <= a <= b <= c <= 10 have a * b * c = 36? Run the code.
print(sum(1 for a in range(1, 11) for b in range(a, 11) for c in range(b, 11) if a * b * c == 36))What is printed?
- A. 6
- B. 5
- C. 4
- D. 7
Correct answer: B. 5
Factor 36 into non-decreasing triples up to 10: 1*1*36 is excluded, while 2*2*9, 2*3*6, 3*3*4, 1*4*9 and 1*6*6 remain.
More Coding Interview Problems questions
- Problem: How many domino tilings does a 3 x 8 board have? Run the recurrence f(n) = 4 f(n-1) - f(n-2) with f(0) = 1, f(1) = 3. python f =…
- Problem: How many Dyck words (balanced bracket sequences) of length 10 exist? Run the DP. python n = 5 C = [1] + [0] n for m in range(1, n…
- Problem: How many permutations of 1..5 have exactly 2 fixed points? Run the code. python from itertools import permutations print(sum(1…
- Problem: What is the number of steps for the Collatz sequence starting at 97 to reach 1? Run the code. python n = 97 c = 0 while n != 1: n…
- Problem: How many subsets of {1, 2, ..., 12} have an odd sum? Run the code. python print(sum(1 for m in range(1 << 12) if sum(i + 1 for i…
- Problem: What is the largest value of x such that x^3 <= 10^12 (integer cube root)? Run the binary search. python lo, hi = 0, 10 6 while…