Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Starting at 0 on a line, a walker takes steps +3, −2, +3, −2, … alternating, with 12 steps in total. How many distinct integer positions does the walker visit (including the start 0)?

  1. A. 13
  2. B. 9
  3. C. 8
  4. D. 6

Correct answer: B. 9

Positions are 0, 3, 1, 4, 2, 5, 3, 6, 4, 7, 5, 8, 6, so the distinct ones are 0..8: 9. Counting visits without de-duplicating gives 13, leaving out the start 0 gives 8, and 6 is just the final position.

More Coding Interview Problems questions

Exams that ask this topic