Given two points i.e. (a, 0) to (b, 0). The task is to check whether it is possible to move from (a,0) to (b,0) or not. One can move as (a, 0), (a+x, 0), (a+x+1, 0), (a, 2*x, 0), (a, 2*x+1, 0)……
Input: a = 3, x = 10, b = 4 Output: No Input: a = 3, x = 2, b = 5 Output: Yes
Approach: An answer will be possible if
- a + n*x = b where n is a non-negative integer.
- a + n*x + 1 = b where n is a positive integer.
(b – a) / x is an integer or (b – a – 1) / x is an integer
(b – a) % x = 0 or (b – a – 1) % x = 0
Below is the implementation of above approach:
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Check if it is possible to reach a number by making jumps of two given length
- Check if it is possible to move from (0, 0) to (x, y) in N steps
- Check if it is possible to move from (0, 0) to (X, Y) in exactly K steps
- Check if possible to move from given coordinate to desired coordinate
- Path traversed using exactly M coins in K jumps
- Minimum number of jumps to reach end
- Climb n-th stair with all jumps from 1 to n allowed (Three Different Approaches)
- Number of jumps for a thief to cross walls
- Minimum block jumps to reach destination
- Reach the numbers by making jumps of two given lengths
- Find if two people ever meet after same number of jumps
- Minimum jumps required to group all 1s together in a given Binary string
- Source to destination in 2-D path with fixed sized jumps
- Traversal of tree with k jumps allowed between nodes of same height
- Minimum steps to reach the Nth stair in jumps of perfect power of 2
- Count minimum factor jumps required to reach the end of an Array
- Move all zeroes to end of array using Two-Pointers
- Minimize steps required to move all 1's in a matrix to a given index
- Minimum revolutions to move center of a circle to a target
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.