Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many ways are there to write 50 as an ordered sum a^2 + b^2 with a, b >= 0? Run the code.
Problem: How many ways are there to write 50 as an ordered sum a^2 + b^2 with a, b >= 0? Run the code.
print(sum(1 for a in range(0, 8) for b in range(0, 8) if a * a + b * b == 50))What is printed?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Only a, b in 0..7 can work; the pairs (1,7), (7,1), (5,5) give the ordered count.
More Coding Interview Problems questions
- Problem: What is the maximum product of 4 consecutive elements of [1, 2, 3, 4, 5, 6]? Run the code. python a = [1, 2, 3, 4, 5, 6]…
- Problem: How many subsequences of 'abcabc' equal the string 'abc'? Run the DP. python s, t = 'abcabc', 'abc' dp = [1] + [0] len(t) for ch…
- Problem: How many strings of length 5 over {a, b, c} have no two adjacent equal characters? Run the code. python from itertools import…
- Problem: How many inversions does [9, 7, 5, 3, 1, 2, 4, 6, 8] have? Run the code. python a = [9, 7, 5, 3, 1, 2, 4, 6, 8] print(sum(1 for i…
- Problem: What is the maximum number of intervals from [[1,5],[2,6],[4,8],[7,9]] that contain a common point? Run the sweep code. python iv…
- Problem: What is the minimum number of coins from {1, 7, 10} that sum to 99? Run the DP. python INF = 10 9 d = [0] + [INF] 99 for v in…