GOLDMANSACHS Coding Question – Solved

5 Live
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.

Asked in: GOLDMANSACHS

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |