Leetcode Problem 858. Mirror Reflection
858. Mirror Reflection
AI Mock Interview
Leetcode Solutions
Mathematical Approach using GCD
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Calculate the greatest common divisor (GCD) of
p
and
q
using Euclid's algorithm.
Calculate the least common multiple (LCM) of
p
and
q
by multiplying
p
and
q
and then dividing by the GCD.
Determine the number of reflections on the east wall by dividing the LCM by
q
.
Determine the number of reflections on the north wall by dividing the LCM by
p
.
If the number of reflections on the east wall is even, the ray hits receptor 0.
If the number of reflections on the east wall is odd and the number of reflections on the north wall is odd, the ray hits receptor 1.
If the number of reflections on the east wall is odd and the number of reflections on the north wall is even, the ray hits receptor 2.
Simulation Approach
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...