Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integer solutions (x, y) satisfy x^2 + y^2 = 65 with x, y >= 0? Run the code.
Problem: How many integer solutions (x, y) satisfy x^2 + y^2 = 65 with x, y >= 0? Run the code.
print(sum(1 for x in range(0, 9) for y in range(0, 9) if x * x + y * y == 65))What is printed?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
The representations of 65 as sums of two squares are 1^2 + 8^2 and 4^2 + 7^2, giving the ordered pairs (1,8), (8,1), (4,7), (7,4).
More Coding Interview Problems questions
- Problem: What is the maximum length of a strictly decreasing subsequence of [9, 4, 6, 3, 8, 1] ? Run the code. python a = [9, 4, 6, 3, 8…
- Problem: How many numbers in [1, 1000] are divisible by 3 and whose digit sum is also divisible by 3? Run the code. python print(sum(1 for…
- Problem: What is the time complexity of finding all prime factors of n up to 10^12 by trial division?
- Problem: Which problem is solved by the 'meet in the middle' technique on a subset-sum instance with n = 40?
- Problem: What does the 'two-phase' Kosaraju algorithm compute?
- Problem: Which best describes the complexity of Dijkstra on a graph with V = 10^5 and E = 10^6 using an array instead of a heap?