Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A grid of 5×5 cells has 'X' blocked cells at (0,2), (1,2), (2,2), (3,2) (row, column, 0-indexed); the rest are open. Cells connect up, down, left and right. What is the size of the largest connected group of open cells?
- A. 10
- B. 25
- C. 20
- D. 21
Correct answer: D. 21
Column 2 is blocked only in rows 0-3, so the open cell (4, 2) joins the left and right halves: 25 − 4 = 21 open cells form one group. Assuming the wall cuts the grid in two gives 10, ignoring the walls gives 25, and dropping the bridge cell gives 20.
More Coding Interview Problems questions
- Problem: On a grid, a diagonal step costs 2 and a straight step costs 1 (moves are up, down, left, right, and the four diagonals). What is…
- Problem: The cycle graph C8 has vertices 0–7 with i adjacent to (i+1) mod 8. How many unordered pairs of vertices are at distance exactly…
- Problem: A height-balanced binary search tree is built over the sorted keys 1, 2, …, 10 by always taking the middle element as the root…
- Problem: Given the parent array p = [−1, 0, 0, 1, 1, 2, 4, 4] for nodes 0–7 (node 0 is the root), how many nodes have exactly one child?
- Problem: A binary tree in level order (None for absent nodes) is [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1]. How many root-to-leaf…
- Problem: Count the odd-length palindromic substrings of "racecarxyz" that are centred at index 3 (the 'e' of "racecar"), where the centre…