Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: How many integer lattice points (x, y) lie on the circle x^2 + y^2 = 25? Run the code.

Problem: How many integer lattice points (x, y) lie on the circle x^2 + y^2 = 25? Run the code.
print(sum(1 for x in range(-5, 6) for y in range(-5, 6) if x * x + y * y == 25))
What is printed?
  1. A. 8
  2. B. 16
  3. C. 4
  4. D. 12

Correct answer: D. 12

The points are (±5,0), (0,±5), (±3,±4) and (±4,±3), giving 4 + 4 + 4 = 12.

More Coding Interview Problems questions

Exams that ask this topic