LeetCode solutions

2645. Pass the Pillow

My accepted Python solution to LeetCode problem 2645, Pass the Pillow, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-31.

python
class Solution:
    def passThePillow(self, n: int, time: int) -> int:
        # One full cycle is 2*(n-1) seconds (go to end and back)
        cycle = 2 * (n - 1)
        time = time % cycle
        
        # If time <= n-1, moving forward (1 to n)
        # Otherwise, moving backward
        if time <= n - 1:
            return 1 + time
        else:
            return n - (time - (n - 1))

Source