You are given a memory block as an integer array of size n.
Your task is to check if a segment of size k starting from the beginning of the array follows an alternating pattern — e.g., 1 0 1 0 ... or 0 1 0 1 ....
Return:
You must use pointer arithmetic only, not array indexing.
Example-1
Input: n = 6, k = 6, mem = [1, 0, 1, 0, 1, 0]
Output: 1
Example-2
Input: n = 6, k = 6, mem = [0, 1, 0, 1, 0, 1]
Output: 1
Example-3
Input: n = 6, k = 6, mem = [1, 1, 0, 1, 0, 1]
Output: 0
Input
6 6 1 0 1 0 1 0
Expected Output
1