Data Structures & AlgorithmsHardGATE CS · DSA
9 people stand in a circle numbered 1 to 9. Counting starts at person 1, and every 3rd person is removed (counting continues from the next person). Simulating with a queue, who survives, and who is removed third?
- A. Survivor 1; third removed 6
- B. Survivor 7; third removed 9
- C. Survivor 1; third removed 9
- D. Survivor 2; third removed 9
Correct answer: C. Survivor 1; third removed 9
Rotate the queue k − 1 times and dequeue the next person each round. Removal order: 3, 6, 9, 4, 8, 5, 2, 7, leaving 1.
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
- A hash-map two-sum returns the first index pair (i, j), i < j, found while scanning left to right. What is printed? python def twosum(a…
- A sorted array was rotated to give [29, 47, 50, 57, 60, 61, 75, 4, 5, 8, 13]. Binary search finds the index of the minimum: while lo < hi…
- Lines of heights [6, 9, 5, 6, 8, 1, 8, 3, 5] stand at x = 0, 1, …, 8. Two pointers find the pair of lines that, with the x-axis, holds the…
- Exponential search: double the bound i (1, 2, 4, …) until a[i] ≥ key or i passes the end, then binary-search the last range. How many…
- A Python 2-D list is created two ways and one cell is set. What is printed? python a = [[0] 3] 3 b = [[0] 3 for in range(3)] a[0][0] = 5…
- A circular queue in an array of size 7 keeps one slot empty to tell full from empty (front = rear means empty; (rear + 1) mod 7 = front…