Data Structures & AlgorithmsModerateTCS NQT · simulation
Problem: How many legal moves does a knight have from the corner (0,0) of an 8 x 8 board? Run the code.
Problem: How many legal moves does a knight have from the corner (0,0) of an 8 x 8 board? Run the code.
moves = [(1, 2), (2, 1), (-1, 2), (-2, 1), (1, -2), (2, -1), (-1, -2), (-2, -1)] print(sum(1 for dx, dy in moves if 0 <= 0 + dx < 8 and 0 <= 0 + dy < 8))What is printed?
- A. 3
- B. 4
- C. 2
- D. 8
Correct answer: C. 2
From the corner only the offsets (1,2) and (2,1) land on the board, so the knight has 2 moves. The destination square is (0+dx, 0+dy), which must lie inside the 8 x 8 board.
More Coding Interview Problems questions
- Problem: What is 7^222 mod 10? Run the code. python print(pow(7, 222, 10)) What is printed?
- Problem: How many integers in [1, 500] are divisible by 4 or by 6? Run the code. python print(sum(1 for x in range(1, 501) if x % 4 == 0…
- Problem: How many ways can [1, 2, 3, 4] be split into two non-empty contiguous parts with equal sums? Run the code. python a = [1, 2, 3…
- Problem: Which algorithm finds all articulation points (cut vertices) of an undirected graph in O(V + E) time using DFS low-link values?
- Problem: Which statement about Kosaraju's algorithm for strongly connected components is correct?
- Problem: Which statement about the Edmonds-Karp maximum-flow algorithm (BFS augmenting paths) is correct?