Goldman Sachs | CoderPad Round

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2022-06-26Added By Anonymous
Source: Link
1.Remaining student

Given size (N) of a group of student and teacher will pick k-th student and remove it from the group, after that teacher will start to count again from the next student and remove k-th student.


If the counting reach the end of group then it will keep counting from the beginning of the group. You need to write a function which take N and K as input and return the index of remaining student.


e.g. N = 5, K =3

1, 2, [3], 4, 5 -> remove 3 from group, start to count from 4

[1], 2, 4, 5 -> reach 5 (the end of group) and continue to count from beginning, remove 1

2, 4, [5] -> remove 5 from group, start to count from 2

[2], 4 -> reomve 2 from the group, 4 is the remaining student

I can brute force it with T = O(n^2) and S = O(n) but I couldn't come up with optimal solution.

I try to google it afterward but I can't find any similar question.


2.Best Average score

Q1 of this one

Comments