Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Starting at (0,0), the robot moves in the string "NNEESSWWNE" with N = up, E = right, S = down, W = left. Count the number of distinct cells it visits (the start included, revisits counted once).

  1. A. 11
  2. B. 9
  3. C. 10
  4. D. 8

Correct answer: B. 9

The path revisits (0,0) and (0,1), so the distinct cells are 11 positions − 2 repeats = 9. Counting every position gives 11, counting moves gives 10, and leaving out the start cell gives 8.

More Coding Interview Problems questions

Exams that ask this topic