Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture

Problem: A grid has 5 cells in a row, each painted red or blue. How many colourings have no two adjacent cells of the same colour?

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

Correct answer: D. 2

Alternating colourings are forced once the first cell is chosen, so there are 2 colourings in total.

More Coding Interview Problems questions

Exams that ask this topic