n people stand in a line labeled 1 to n. Person 1 starts with a pillow, and every second the holder passes it to the next person. When the pillow reaches the end of the line, the direction reverses. Given n and time, return the label of the person holding the pillow after time seconds.
n people stand in a line labeled 1 to n. Person 1 starts with a pillow, and every second the holder passes it to the next person. When the pillow reaches the end of the line, the direction reverses. Given n and time, return the label of the person holding the pillow after time seconds.
Example 1:
Input: {"n":4,"time":5}
Output: 2
Constraints:
2≤n≤1000
1≤time≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":4,"time":5}
Person 1 holds the pillow at second 0. Walking from one end of the line to the other takes n - 1 = 3 passes.
the line at second 0 (pillow moving right →)
1
2
3
4
holder over time: each straight run is one trip of 3 seconds