Data Structures & AlgorithmsHardTCS NQT · Accenture

A grid has the rows ..#.., .##.., ....., #.#.# (where '.' is open and '#' is a wall; all rows have length 5). Starting from the top-left cell, how many open cells can be reached moving up, down, left or right?

  1. A. 15
  2. B. 16
  3. C. 18
  4. D. 14

Correct answer: D. 14

A breadth-first search from the start marks every reachable open cell; the walls '#' block movement. Cells cut off by walls are not counted.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic