
Ninja wants to travel from his house to his best friend’s house. The houses are located on a 2D coordinate plane, with Ninja’s house being situated at the origin. Ninja’s friend’s house is located somewhere on the x-axis. Now bombs are located at every point with an odd x-coordinate. Ninja can reach his friend’s house if it is an even coordinate else, he cannot reach there because there is a bomb placed at that point. There is a dragon who doesn’t let ninja use, modulus operator.
You are given an integer ‘N’ denoting the x-coordinate of Ninja’s friend’s house. Can Ninja reach his friend’s house? If yes, then return 1 else, return 0. Can you help him find without using the modulus operator?
The first line contains ‘T’, denoting the number of test cases.
Each test case contains a single integer ‘N’, denoting the x-coordinate of Ninja’s friend’s house.
Output Format:
For each test case, return '1' if Ninja can reach his friend’s house else return '0'.
Note:
You cannot make use of the modulus operation.
You are not required to print the expected output; it has already been taken care of.
Just implement the function.
1 <= T <= 10
1 <= N <= 10^9
Time Limit: 1 sec
2
2
1
1
0
In the first test case, the x-coordinate of his friend’s house is, even so, Ninja can reach so 1 is returned.
In the second test case, the x-coordinate of his friend’s house is, odd so, Ninja can reach so 0 is returned.
2
7
2
0
1
Can you check whether a point is even or not?
The key here is to check whether a given number is even or not.
The steps are as follows:
O(1)
A mathematical operation was performed on the given input and no loop was used hence overall complexity is O(1).
O(1)
As we are not using any extra space. Hence, the overall space complexity is O(1).