Data Structures & AlgorithmsVery hardSSC CGL Tier 2 · Product Company SDE
Problem: Josephus game: n = 37 people stand in a circle numbered 1 to 37. Starting from person 1, every 4th person is removed (counting continues around the circle, skipping removed people). What is the number of the last person left?
- A. 34
- B. 19
- C. 33
- D. 1
Correct answer: A. 34
Simulate with index i = (i + k − 1) mod size, removing persons 4, 8, 12, …; the survivor is 34. Counting every 3rd person (stepping k − 1 = 3 as if it were k) gives 19, returning the 0-indexed Josephus recurrence without the + 1 gives 33, and counting every 5th person gives 1.
More Coding Interview Problems questions
- Problem: A deque starts empty. Operations in order: pushback(5), pushfront(2), pushback(8), popfront(), pushfront(9), pushback(1)…
- Problem: How many integers x in the range 1 ≤ x ≤ 1000 have exactly 4 set bits in their binary representation?
- Problem: A staircase can be climbed by steps of size 1, 3 or 4. How many distinct ordered sequences of steps climb exactly 13 stairs?
- Problem: What is the length of the longest strictly increasing subsequence of the sequence 10, 9, 2, 5, 3, 7, 101, 18, 4, 6, 8, 1, 12?
- Problem: Coins of denominations 5, 12 and 20 are available in unlimited supply. What is the minimum number of coins needed to make exactly…
- Problem: The list [25, 14, 9, 31, 7, 18, 3, 12] is turned into a min-heap in place with heapify (standard bottom-up sift-down, 0-indexed)…