Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many integers in [1, 1000] are both perfect squares and perfect cubes? Run the code.
Problem: How many integers in [1, 1000] are both perfect squares and perfect cubes? Run the code.
print(sum(1 for x in range(1, 1001) if any(k * k == x for k in range(1, 32)) and any(k ** 3 == x for k in range(1, 11))))What is printed?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
A number that is both a square and a cube is a sixth power, and the sixth powers up to 1000 are 1, 64 and 729.
More Coding Interview Problems questions
- Problem: How many integers in [1, 100] are divisible by neither 2 nor 3? Run the code. python print(sum(1 for x in range(1, 101) if x % 2…
- Problem: How many ordered pairs (a, b) with 1 <= a, b <= 9 make a b a perfect square? Run the code. python print(sum(1 for a in range(1…
- Problem: What is the time complexity of Johnson's all-pairs shortest path algorithm on a sparse graph with V vertices and E edges?
- Problem: Which problem asks for the minimum number of rectangles of size 1 x 2 needed to tile a board with some cells removed (domino…
- Problem: What does the Hall condition require for a bipartite graph to have a matching covering the left side?
- Problem: Which algorithm solves the single-source shortest path problem in O(E) time on a directed acyclic graph with arbitrary edge…