Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Six people stand in a circle numbered 1 to 6. Starting from person 1, every 4th person (counting the start as 1) is removed until one remains. Which person survives?
- A. 6
- B. 4
- C. 5
- D. 7
Correct answer: C. 5
Use a circular queue: rotate three times, then remove the front. Off-by-one in the rotation count is the common mistake.
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 contiguous subarrays of [1, 3, 2, 4, 6, 5] have (maximum minus minimum) at most 2?
- How many non-empty contiguous subarrays of [2, -1, -1, 3, -2, 1, 1, -2, 0] have a sum of exactly 0?
- What is the maximum sum over all non-empty contiguous subarrays of [3, -8, 4, -1, 2, -6, 5, 1, -7, 4]?
- For the circular array [5, -3, 4, -6, 2, 3, -1, 4], what is the maximum sum of a non-empty subarray when the array is treated as circular…
- How many index pairs i < j satisfy a[i] + a[j] = 10 for a = [7, 1, 5, 3, 9, 2, 8, 4, 6, 0]?
- What is the length of the longest contiguous subarray of [1, 2, 1, 2, 3, 2, 2, 4, 1, 1, 1] that contains at most 2 distinct values?