Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: How many ordered pairs (x, y) with 1 <= x, y <= 12 satisfy x^2 + y^2 <= 100? Run the code.

Problem: How many ordered pairs (x, y) with 1 <= x, y <= 12 satisfy x^2 + y^2 <= 100? Run the code.
print(sum(1 for x in range(1, 13) for y in range(1, 13) if x * x + y * y <= 100))
What is printed?
  1. A. 67
  2. B. 90
  3. C. 69
  4. D. 38

Correct answer: C. 69

For x = 1..9 the admissible y counts are 9, 9, 9, 9, 8, 8, 7, 6, 4 = 69. A strict < 100 drops (6,8) and (8,6) for 67, allowing 0 gives 90, and counting only x ≤ y gives 38.

More Coding Interview Problems questions

Exams that ask this topic