Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Mirror Reflection

XPChallenge Points: 20
levelLevel: Medium

A square hall has mirrors on all four walls.
Receptors are fixed at three corners:
• 0 → northeast corner
• 1 → southeast corner
• 2 → northwest corner
A laser starts at the southwest corner and travels at a 45° angle upward.
The room’s side length is p.
The laser first hits the east wall at a vertical distance q from receptor 0.
Your task: Find which receptor number (0, 1, or 2) the laser touches first.

Example 1:

Input: p = 2, q = 1

Output: 2

Explanation:

The ray bounces and first meets the receptor at corner 2.

Example 2:

Input: p = 3, q = 1

Output: 1

Explanation:

After reflections, the ray reaches receptor 1 first.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result