#858
Mirror Reflection
specialist · 755 · lc medium +31 · verified · 61.8% accepted · 1,151 likes · top 62%
Description
A square mirrored room has walls of length p. Receptors numbered 0, 1, and 2 occupy three of the four corners (all except the southwest corner). A laser is fired from the southwest corner and first strikes the east wall at a height of q above the southeast corner (receptor 0).
Given p and q, return the label of the receptor the laser reaches first.
The input guarantees the laser eventually reaches a receptor.
Example 1:
Input: p = 2, q = 1
Output: 2
Explanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.
Example 2:
Input: p = 3, q = 1
Output: 1
Code
1
2
3