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

Exams that ask this topic