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?
- A. 2
- B. 0
- C. 3
- 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
- Problem: The permutation [2, 1, 4, 3] is processed by a single stack: input elements are pushed in order and popped whenever the popped…
- Problem: How many integers from 1 to 500 are coprime to 30 (share no prime factor with 30 = 2·3·5)?
- Problem: What is the sum of all prime numbers less than 30?
- Problem: How many bits are needed to write 10^9 in binary (the number of bits in its binary representation)?
- Problem: Reverse the 8-bit binary representation of 13 (00001101) and report the resulting unsigned value in decimal.
- Problem: What is the smallest positive integer x such that 1 + 2 + … + x is at least 100?