Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Maintain two integer variables, direction and i, where direction denotes the current direction in which the pillow should pass, and i denotes an index of the person holding the pillow.
While time is positive, update the current index with the current direction. If the index reaches the end of the line, multiply direction by - 1.
Solve with full IDE support and test cases