Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Odd Even
EASY
10 mins
1 upvotes
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Odd Even

Contributed by
Sachin_f78a
Easy
yellow-spark
0/40
Avg time to solve 10 mins
Success Rate 86 %
Share
1 upvotes

Problem Statement

Alice has two numbers, 'X' and 'Y'. He is asked to perform the following operations any number of times.

Alice adds 1 to 'X' if 'X' is odd. Alice adds 2 to 'X' if 'X' is even. Will he be able to make 'X' equal to 'Y'?

Return 1 if 'X' can be made equal to 'Y' using the above operations any number of times(possibly 0) and 0 otherwise.

Note: Assume 1-based indexing.

For example:
Let 'X' = 3 and 'Y' = 6, Alice adds 1 to 'X' since 'X' is odd. Now 'X' will become 4. Then, Alice will add 2 to 'X', since 'X' is even, and it will become 6. 'X' becomes equal to 'Y'. Hence we will return 1 as the answer.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:-
2
4 8
1 1
Sample Output 1:-
1
1
Explanation of sample input 1:-
First test case:- 
In 1st operation, Alice will add 2 to 'X' as 'X' is even. Now, 'X' is 6. Again, in the 2nd operation, Alice will add 2 to 'X'. Now 'X' is 8, which is equal to 'Y'. So, the answer is 1.

Second test case:-
'X' is already equal to 'Y'. So, the answer is 1.
Sample Input 2:-
2
4 9 
7 8
Sample Output 2:-
0
1
Reset Code
Full screen
Auto
copy-code
Console