Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A grid has '.' for open cells and '#' for walls: rows are ".#..#", ".#.##", "...#.", "##..#" and "#...." (5×5). Cells connect only up, down, left and right. How many connected groups of open cells are there?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
A flood fill from each unvisited open cell counts one group per fill. Counting open cells or walls instead of groups is the common mistake.
More Coding Interview Problems questions
- Problem: How many simple cycles (cycles that visit no vertex twice, with 3 or more vertices) does the complete undirected graph K4 on…
- Problem: A rooted tree (root 1) has children lists: 1: [2, 3], 2: [4, 5, 6], 3: [7], 4: [], 5: [8], 6: [], 7: [9], 8: [], 9: []. How many…
- Problem: For the same rooted tree as the previous question (root 1: children 2, 3; 2: children 4, 5, 6; 3: child 7; 5: child 8; 7: child…
- Problem: In a binary tree with 7 nodes in level order [10, 5, 15, 2, 7, 12, 20] (missing children are shown as absent, so the array…
- Problem: Three sorted rows are [1, 5, 9, 14], [2, 6, 10, 15] and [3, 7, 11, 16]. Merging all rows into one sorted sequence, what is the…
- Problem: What is the length of the longest substring of "abcabcbb" with all characters distinct?