A quick post on the first problem from Hackerrank Weekly #5.
After a quick analysis of the problem statement, you can reformulate it in the following way:
You're given the array .
After that, there are queries. For each query you have to print the parity of the following formula:
Let's take a query . In order to decide the parity for that query, you have to decide what's the parity of raised to some power .
For any , it's sufficient to check the parity of , because if is even, then after raising to any positive it's still even and if is odd, then after raising to any positive it remains odd.
The only other case is when (it's guaranteed that there are no two adjacent 0 in the array , so never happens).
We can observe that if and only if . If that's the case then parity of doesn't matter and the result is always odd, because we raise a non negative number to -th power.
The time complexity of that method is .