Data Structures & AlgorithmsHardICPC regional · Product Company SDE
Problem: A knight starts at square (0,0) on an infinite chessboard. What is the minimum number of knight moves needed to reach square (4,5)?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
BFS on the knight's move graph gives the minimum number of moves; the parity of the square colour alone does not decide the count. Using the Manhattan distance divided by 3 is a common but wrong shortcut.
More Coding Interview Problems questions
- Problem: The complete graph K6 has 15 edges. A perfect matching of 3 disjoint edges is removed. How many edges remain?
- Problem: What is the chromatic number of the cycle graph C5 (5 vertices in a single cycle)? The chromatic number is the least number of…
- Problem: What is the independence number of the cycle graph C7 (the maximum number of vertices with no two adjacent in the 7-cycle)?
- Problem: The binary search tree is built by inserting 8, 3, 10, 1, 6, 14, 4, 7, 13 in this order. How many nodes lie at the maximum depth…
- Problem: A binary tree is given in level order with None for missing children: [1, 2, 3, None, 4, 5, None, 6]. In this array, node at…
- Problem: The right-side view of a binary tree lists the rightmost node at each depth from top to bottom. For the tree with root 1…