Leetcode Problem 2543. Check if Point Is Reachable

2543. Check if Point Is Reachable

Leetcode Solutions

Reverse Engineering with GCD

  1. Check if targetX or targetY is 1. If so, the other must be a power of 2 for the target to be reachable.
  2. Calculate the GCD of targetX and targetY.
  3. If the GCD is not a power of 2, return false.
  4. Divide both targetX and targetY by the GCD.
  5. If either targetX or targetY is now 1, the other must be a power of 2 for the target to be reachable.
  6. If both targetX and targetY are greater than 1 and odd, return false.
  7. Otherwise, return true.
UML Thumbnail

Iterative Backtracking

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...