Ctrl K

Hot Potato Down the Row

Easy
players players stand in a row, numbered from 1 to players. At the start, player 1 holds the potato. Every second, whoever holds it passes it to the next player along the row. When it reaches the last player it turns around and travels back; at the first player it turns around again, and so on. Return the number of the player holding the potato after seconds seconds.
Example 1
players=3, seconds=6 → 3

The potato goes 1 → 2 → 3 → 2 → 1 → 2 → 3, so after 6 seconds player 3 has it.

Example 2
players=5, seconds=2 → 3

1 → 2 → 3: the potato has not reached the end of the row yet.

Example 3
players=4, seconds=7 → 2
Constraints
  • 2 ≤ players ≤ 1000
  • 1 ≤ seconds ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyFold the Digits Down to One EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings EasyGrowing Handouts Around the Circle Easy
loading Python…
Input
players=3, seconds=6
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.