We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Some solutions published below omit the first condition (x>y) but it works only because there are no test cases with x>y and arr[x-1] even (you can make your own test case to see that it would fail in such event.
Explanation: x>y is odd, odd^anything is odd, anything^0 is odd, everything else is even.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Even Odd Query
You are viewing a single comment's thread. Return to all comments →
Python oneliner:
Some solutions published below omit the first condition (
x>y
) but it works only because there are no test cases withx>y
andarr[x-1]
even (you can make your own test case to see that it would fail in such event.Explanation: x>y is odd, odd^anything is odd, anything^0 is odd, everything else is even.