Data Structures & AlgorithmsHardGATE CS · competitive programming
Ten people stand in a circle numbered 1 to 10. Counting from person 1, every 3rd person is eliminated and removed, and counting continues around the circle. Who survives (1-based)?
- A. 3
- B. 4
- C. 7
- D. 5
Correct answer: B. 4
The eliminations run 3, 6, 9, 2, 7, 1, 8, 5, 10, so the survivor is person 4. Person 7 is the survivor for a different step size, the trap.
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
- The same rule, with every 3rd person eliminated, applies to n = 41 people. Who survives (1-based)?
- 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…