Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A 2×4 grid has a wall at (0,2) (row, column, 0-indexed); all other cells are open. Moves go up, down, left or right. What is the shortest distance from (0,0) to (1,3)?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
The wall at (0,2) forces the route through row 1: (0,0)→(1,0)→(1,1)→(1,2)→(1,3), which takes four moves. The Manhattan distance of 4 is achievable here because the detour is along the bottom row.
More Coding Interview Problems questions
- Problem: The complete directed graph on 4 vertices has an arc in both directions between every pair of distinct vertices. How many…
- Problem: The path graph P4 has vertices 1–4 and edges 1-2, 2-3, 3-4. How many edges does its complement graph (on the same vertices…
- Problem: A complete binary tree has 15 nodes (height 3, all levels full). How many of its nodes are leaves?
- Problem: The string "abba" has how many palindromic substrings (counted by index range)?
- Problem: How many occurrences of "ab" are in "ababab" when occurrences may overlap?
- Problem: In the string "dvdf", what is the length of the longest substring with all distinct characters?