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?
  1. A. 6
  2. B. 5
  3. C. 4
  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

Exams that ask this topic