Pass the Pillow Problem
Pass the Pillow Problem — ExecCode Easy DSA Practice
Solve the Pass the Pillow problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given the two positive integers n and time, return the index of the person holding the pillow after time seconds. Your task is to there are n people standing in a line labeled from 1 to n. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pillow reaches the end of the line, the direction changes, and people continue passing the pillow in the opposite direction. Return the required answer exactly as shown in the examples.
Examples
Input {"n": 4, "time": 5}; Output 2. Input {"n": 3, "time": 2}; Output 3
Constraints
2 <= n <= 1000 1 <= time <= 1000
Practice Pass the Pillow free on ExecCode. Browse DSA problems, topic map, and placement guides.