Check if point ( X , Y ) can be reached from origin ( 0 , 0 ) with jump of 1 and N perpendicularly simultaneously | Java code for the above approach ; Function to check if ( X , Y ) is reachable from ( 0 , 0 ) using the jumps of given type ; Case where source & destination are the same ; Check for even N ( X , Y ) is reachable or not ; If N is odd and parity of X and Y is different return , no valid sequence of jumps exist ; Driver Code
import java . io . * ; class GFG { static String checkReachability ( int N , int X , int Y ) { if ( X == 0 && Y == 0 ) { return " YES " ; } if ( N % 2 == 0 ) { return " YES " ; } else { if ( X % 2 != Y % 2 ) { return " NO " ; } else { return " YES " ; } } } public static void main ( String [ ] args ) { int N = 2 ; int X = 5 , Y = 4 ; System . out . println ( checkReachability ( N , X , Y ) ) ; } }