3463. Alternating Groups I
My accepted Python solution to LeetCode problem 3463, Alternating Groups I, running in 60ms.
- Difficulty: Easy
- Python
- Runtime 60ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 60ms, memory 17.3MB, accepted 2025-12-30.
class Solution:
def numberOfAlternatingGroups(self, colors: List[int]) -> int:
n = len(colors)
count = 0
for i in range(n):
left = colors[(i - 1) % n]
mid = colors[i]
right = colors[(i + 1) % n]
if mid != left and mid != right:
count += 1
return count