Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The 0/1 matrix [[1,0,1],[1,1,0],[0,1,1]] is considered. A 'plus' is a centre cell with value 1 whose four neighbours (up, down, left, right) all exist and are also 1. How many pluses are in the matrix?

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. 3

Correct answer: A. 0

Test each interior cell whose four neighbours exist. Border cells can never be plus centres, since one neighbour lies outside the matrix.

More Coding Interview Problems questions

Exams that ask this topic