LeetCode solutions

2680. Count Collisions of Monkeys on a Polygon

My accepted Python solution to LeetCode problem 2680, Count Collisions of Monkeys on a Polygon, running in 0ms.

  • Difficulty: Medium
  • Python
  • Runtime 0ms
  • Memory 17.5MB

Read the problem on LeetCode View on GitHub

Python

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

python
class Solution:
    def monkeyMove(self, n: int) -> int:
        MOD = 10**9 + 7
        # Total ways = 2^n (each monkey can go clockwise or counter-clockwise)
        # No collision happens only when all go same direction (2 ways)
        # Answer = 2^n - 2
        return (pow(2, n, MOD) - 2) % MOD

Source