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?
- A. 67
- B. 90
- C. 69
- 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
- Problem: How many lattice points (x, y) with x >= 0, y >= 0 and x + y <= 10 lie in the triangle? Run the code. python print(sum(1 for x in…
- Problem: What is the sum of the ASCII codes of the characters of 'hello'? Run the code. python print(sum(ord(c) for c in 'hello')) What is…
- Problem: What is the length of the longest strictly increasing contiguous subarray of [3, 4, 5, 1, 2, 3, 4, 5, 6]? Run the code. python a…
- Problem: What is the minimum number of cuts needed to partition 'abcde' into palindromes? Run the DP. python s = 'abcde' n = len(s) pal =…
- Problem: How many two-digit numbers have a digit sum that is a prime number? Run the code. python def isp(n): return n > 1 and all(n % d…
- Problem: How many subarrays of [1, 2, 2, 3, 3, 3] have all equal maximum and minimum values? Run the code. python a = [1, 2, 2, 3, 3, 3]…