46. Detect Alternating Pattern

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:

  • 1 if the segment follows an alternating pattern
  • 0 if not

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


 

Loading...

Input

6 6 1 0 1 0 1 0

Expected Output

1