Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created March 9, 2025 22:49
Show Gist options
  • Save Ifihan/16fc85180ebad285d0e50cb5ffe8c81f to your computer and use it in GitHub Desktop.
Save Ifihan/16fc85180ebad285d0e50cb5ffe8c81f to your computer and use it in GitHub Desktop.
Alternating Groups II

Question

Approach

I iterate through all possible starting positions in the circular array. For each starting position, I check if the k-length subarray follows the alternating pattern.

Since the array is circular, I use modulo indexing to wrap around. If a subarray follows the alternating pattern, I increment the count. I kept on getting TLE and all my other approaches were not working so I used the editorial

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment