Given a point (x, y). Find whether it is possible or not to move from (0, 0) to (x, y) in exactly n steps. 4 types of steps are valid, you can move from a point (a, b) to either of (a, b+1), (a, b-1), (a-1, b), (a+1, b)
Input: x = 0, y = 0, n = 2 Output: POSSIBLE Input: x = 1, y = 1, n = 3 Output: IMPOSSIBLE
In the shortest path, one can move from (0, 0) to (x, y) in |x| + |y|. So, it is not possible to move from (0, 0) to (x, y) in less than |x| + |y| steps. After reaching one can take two more steps as (x, y) -> (x, y+1) -> (x, y).
So, it is possible if
n >= |x| + |y| and ( n-( |x| + |y| ) ) % 2 = 0.
Below is the implementation of the above approach:
- Check if it is possible to move from (0, 0) to (X, Y) in exactly K steps
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Minimize steps required to move all 1's in a matrix to a given index
- Check if it is possible to move from (a, 0) to (b, 0) with given jumps
- Check if it is possible to reach (x, y) from origin in exactly Z steps using only plus movements
- Check if possible to move from given coordinate to desired coordinate
- Move all zeroes to end of array using Two-Pointers
- Number of blocks in a chessboard a knight can move to in exactly k moves
- Minimum revolutions to move center of a circle to a target
- Count the total number of squares that can be visited by Bishop in one move
- Maximum money that can be withdrawn in two steps
- Find the number of stair steps
- Largest number N which can be reduced to 0 in K steps
- Convert 1 into X in min steps by multiplying with 2 or 3 or by adding 1
- Count minimum steps to get the given desired array
- Count the minimum steps to reach 0 from the given integer N
- Probability of reaching a point with 2 or 3 steps at a time
- Generate array with minimum sum which can be deleted in P steps
- Number of steps required to reach point (x,y) from (0,0) using zig-zag way
- Find the minimum number of steps to reach M from N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.