SALESFORCE Coding Question β Solved
In a Salesforce environment, there are n developers working on a collaborative task in a workspace, where they plan to transfer a debug log sequentially. Each developer has a unique ID in the range of 1 to n, inclusive. The developer with ID i will always transfer the log to the developer specified at logReceiver[i], and this transfer occurs every second. Developer 1 always starts with the debug log, and a developer always transfers the log to another developer.
Determine which developer has the debug log after k seconds have passed.
Example: logReceiver = [2, 4, 1, 5, 3], k = 6. After 6 seconds, the debug log will be with developer 2.
Function Description:
Complete the function logTransferReceiver in the editor below.
logTransferReceiver has the following parameters:
int logReceiver[n]: the i-th developer will transfer the debug log to the developer indicated in logReceiver[i].
int k: the duration (in seconds) for which the log is being transferred.
Return:
int: the developer holding the debug log at time = k.
Constraints:
2 β€ n β€ 2Γ10^5
1 β€ logReceiver[i] β€ n (logReceiver[i] β i)
1 β€ k β€ 10^12
Input Format For Custom Testing:
Sample Case 0:
logReceiver[] size n = 4
logReceiver = [3, 1, 4, 2]
Sample Input For Custom Testing:
STDIN
2
5
Sample Output:
k = 5
2
Explanation:
The log is transferred in the following sequence, starting with Developer 1 at time = 0: