Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A 3×4 grid has walls '#' at (0,2), (1,1), (2,3). Moves go up, down, left and right through open cells. Starting from (0,0), how many open cells are at shortest-path distance exactly 4?
- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
BFS assigns each reachable open cell its shortest distance, and the question counts those at exactly four steps. Cells that are reachable but farther away, or walls, are excluded.
More Coding Interview Problems questions
- Problem: A directed graph has arcs 0→1 (0), 1→2 (3), 0→2 (5), 2→3 (0), 1→3 (7), 3→4 (2), 2→4 (4), 4→5 (1), 0→5 (9). Arc weights may be…
- Problem: A tree on 6 nodes has edges 1-2, 1-3, 1-4, 4-5, 4-6. How many pairs of edges share a common endpoint (that is, unordered pairs of…
- Problem: The string "cbaebabacd" is scanned with windows of length 3. How many windows are anagrams of "abc" (same letters, same counts…
- Problem: The string "aaaaa" is split into non-overlapping occurrences of "aa" from left to right (greedily taking each match). How many…
- Problem: In the string "aabcbcdbca", what is the length of the shortest substring that contains exactly 3 distinct letters?
- Problem: What is the length of the longest palindromic substring of "abcbxa" that can be made a palindrome after deleting at most one…