As reported: Goldman Sachs CoderPad round (~4 years of experience, Bangalore, 2026): students sit in a circle with roll numbers given as a list such as
2, 3, 1, 4, 5; the teacher is given a starting roll number, removes that student, and keeps removing students around the circle until one is left — for the list above and start3, the students leave in the order 3, 5, 1, 4 and the answer is 2. Time and space complexity were asked.
Students sit in a circle in the order given by rolls (distinct roll numbers; after the last student comes the first). The teacher removes the student whose roll number is start. From then on, after each removal the teacher counts forward around the remaining students, starting with the student right after the one just removed, as many places as the removed student's roll number, and removes the student the count lands on.
Return the roll number of the last student left.
Example 1
rolls = [2,3,1,4,5], start = 3
-> 2
remove 3; count 3: 1, 4, 5 -> remove 5
count 5 among [2,1,4]: 2, 1, 4, 2, 1 -> remove 1
count 1 among [2,4]: 4 -> remove 4 -> 2 is left
Example 2
rolls = [1,2,3,4], start = 1
-> 3
Constraints: 1 ≤ rolls.length ≤ 2000; roll numbers are distinct, 1 ≤ rolls[i] ≤ 10^9; start is one of them.
Code runner format: one JSON value per line: rolls, then start. Implement lastStudent(rolls, start); the harness prints the roll number.