GOLDMANSACHS Coding Question β Solved
A birthday party was attended by N number of kids, and each kid was given a unique ID ranging from 1 to N. As a return gift, there are T toys that must be distributed to the kids.
The host decided the best way to do this is by sitting the kids down in a circle (ordered by ascending ID), and then, starting with a random number D (between 1 and N), distribute one toy at a time to each sequentially numbered kid until all toys are distributed.
For example, if the host picks a random number D = 2, the gift distribution order would be: (2, 3, 4, 5, ... N-1, N, 1, 2, 3, 4, ...) until all T toys are distributed. The very last toy is damaged.
Your task is to determine which kid will receive the last (damaged) toy, so they can be informed and asked to exchange it at the shop.
Input:
- N (number of kids)
- T (number of toys)
- D (starting ID where distribution begins)
Output:
Print the ID of the last kid who will receive the damaged toy.
Constraints:
- 1 β€ N β€ 1000
- 1 β€ T β€ 1000
- 1 β€ D β€ N
Sample Input:
5
2
1
Sample Output:
2
Explanation:
There are N=5 kids and T=2 toys. Distribution starts at kid ID 1 (D=1). The distribution follows this pattern:
- Kid 1 receives the first toy.
- Kid 2 receives the second (and last) toy.
Thus, we must inform Kid 2 about the damaged toy, so we print `2` on a new line.