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?
- A. 8
- B. 16
- C. 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
- Problem: How many integers in [1, 10000] have decimal digits summing to 12? Run the code. python print(sum(1 for x in range(1, 10001) if…
- Problem: What is the length of the longest palindromic subsequence of 'character'? Run the DP. python def lps(s): n = len(s) dp = [[0] n…
- Problem: What is the minimum number of characters to insert to make 'leetcode' a palindrome? Use length minus longest palindromic…
- Problem: How many binary strings of length 6 contain no three consecutive 1s? Run the code. python import itertools print(sum(1 for t in…
- Problem: How many derangements (permutations with no fixed point) of 1..6 exist? Run the code. python from itertools import permutations…
- Problem: How many permutations of 0..4 have exactly one inversion? Run the code. python from itertools import permutations print(sum(1 for…