Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 100] are sums of two positive cubes? Run the code.
Problem: How many integers in [1, 100] are sums of two positive cubes? Run the code.
print(len({a ** 3 + b ** 3 for a in range(1, 5) for b in range(a, 5) if a ** 3 + b ** 3 <= 100}))What is printed?- A. 9
- B. 6
- C. 15
- D. 13
Correct answer: A. 9
Sums with a ≤ b ≤ 4 and value ≤ 100: 2, 9, 16, 28, 35, 54, 65, 72, 91, so 9. Requiring a < b gives 6, counting ordered pairs without the set gives 15, and allowing 0³ adds 4 more for 13.
More Coding Interview Problems questions
- Problem: How many distinct sums of two different elements of [1, 2, 4, 8] are there? Run the code. python from itertools import…
- Problem: How many ways are there to place 2 non-attacking rooks on a 4 x 4 board? Run the code. python from itertools import combinations…
- Problem: How many integers in [1, 1000] have exactly three distinct decimal digits? Run the code. python print(sum(1 for x in range(1…
- Problem: How many primes p <= 200 have p + 6 also prime? Run the code. python def isp(n): return n > 1 and all(n % d for d in range(2…
- Problem: How many integers in [1, 2000] have an odd number of positive divisors? Run the code. python print(sum(1 for x in range(1, 2001)…
- Problem: How many 3-element subsets of {1, ..., 10} have sum 15? Run the code. python from itertools import combinations print(sum(1 for c…