Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: Josephus with step 3: 10 people numbered 1 to 10 stand in a circle. Starting from person 1, count 3 people and eliminate the third, repeating around the shrinking circle until one remains. Who survives?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Counting three means the eliminated index advances by two from the current person, with wrap-around. Eliminating the second person instead changes the survivor.
More Coding Interview Problems questions
- Problem: The sequence x0 = 1 and x(n+1) = (3·x(n) + 1) mod 7 is generated. The first repeated value appears at some step. What is the…
- 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…
- 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)?