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?
- A. 15
- B. 16
- C. 18
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A list holds 1, 1, 2, 2, 2, 3, 1, 1. Consecutive duplicates are merged into one node each. What is the sum of the values left in the list?
- How many distinct strings can be obtained from abc by swapping two adjacent characters at most once (including the original string)?
- A passenger count changes by +3, -1, +2, -2, +4, -3 at successive stops, starting from 0. What is the maximum number of passengers on…
- How many integers x in [1, 500] have digit sum equal to 10?
- How many unordered pairs {a, b} with a < b and 1 <= a, b <= 30 have a b a perfect square?
- An array is [1, 2, 1, 2, 1, 2] (indices 0 to 5). How many pairs of even-indexed positions i < j hold equal values?