Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2
The same rule, with every 3rd person eliminated, applies to n = 41 people. Who survives (1-based)?
- A. 16
- B. 28
- C. 31
- D. 40
Correct answer: C. 31
The Josephus recurrence J(n) = (J(n−1) + 3) mod n with J(1) = 0 gives 30 in 0-based terms, that is person 31. Simulating the queue gives the same answer.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many permutations of 1..5 can be produced by pushing 1, 2, 3, 4, 5 in order onto a stack and popping at any moment?
- How many pairs i < j in [2, 7, 3, 5, 8, 4] have A[i] + A[j] divisible by 3?
- How many non-empty contiguous subarrays of [4, 5, 0, 2, 3, 1] have a sum divisible by 5?
- Finding the k-th smallest element with a median-of-medians pivot is used as a deterministic selection method. What is its worst-case time…
- Four sorted lists of sizes 7, 5, 3 and 2 are merged pairwise, always merging the two currently smallest lists first. What is the total…
- How many non-empty contiguous subarrays of [3, 5, 6, 1, 2, 3, 4] have bitwise XOR equal to 0?