Data Structures & AlgorithmsModerateTCS NQT · CAT
Problem: On a 3×3 grid, each cell is labelled with its row times column (1-indexed). The number of cells whose label is a perfect square is what value?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
The labels are the products r·c for r, c in 1 to 3. The perfect-square labels are 1, 4 and 9, which occur at (1,1), (2,2) and (3,3), so the count is 3.
More Coding Interview Problems questions
- Problem: How many integers in [1, 100] have exactly 3 divisors? Run the code. python print(sum(1 for x in range(1, 101) if sum(1 for d in…
- Problem: What is the sum of the digits of 3^20? Run the code. python print(sum(int(c) for c in str(3 20))) What is printed?
- Problem: How many paths of length 3 exist in a complete graph K4 that start and end at different vertices? Run the code (count ordered…
- Problem: What is the number of integers in [1, 1000] whose digits are all odd? Run the code. python print(sum(1 for x in range(1, 1001) if…
- Problem: What is the length of the longest subarray of [5, 1, 4, 2, 3, 6] whose elements can be sorted to form consecutive integers? Run…
- Problem: How many integers from 1 to 1000 are not divisible by any of 2, 3, 5 and 7? Run the code. python print(sum(1 for x in range(1…