Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: How many ordered pairs (a, b) with 1 <= a, b <= 9 make a b a perfect square? Run the code.
Problem: How many ordered pairs (a, b) with 1 <= a, b <= 9 make a * b a perfect square? Run the code.
print(sum(1 for a in range(1, 10) for b in range(1, 10) if int(round((a * b) ** 0.5)) ** 2 == a * b))What is printed?
- A. 17
- B. 13
- C. 8
- D. 9
Correct answer: A. 17
Ordered digit pairs with a square product number 17 (e.g. (1,4), (2,8), (3,3), (4,9)). Unordered pairs give 13, excluding a = b gives 8, and requiring both digits to be squares gives 9.
More Coding Interview Problems questions
- 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…
- Problem: Which statement about the Edmonds-Karp algorithm's number of augmentations is correct?
- Problem: Which problem is solved by the Floyd-Warshall algorithm in the presence of negative edges but no negative cycle?