Unable to understand your code well.
Here’s my code. My solution is just simply generate an array of 1,2,1,2…
and another array of 2,1,2,1 and check array with both of them and see if pattern matches in any of them where a[i]!=-1.
That’s a very nice approach. Thanks