Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A ball starts at position 0 on a track from 0 to 10 and moves 3 units per second. At each boundary it reverses direction (bounces). Where is the ball after 7 seconds?

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

Correct answer: D. 1

Reflect the overshoot past a wall and reverse the direction. Clamping the position to the wall instead of reflecting gives a different final position.

More Coding Interview Problems questions

Exams that ask this topic