The Mirror Reflection problem models a laser beam bouncing inside a square room with mirrors on three walls and receptors at specific corners. Given the room size p and the distance q the laser travels between reflections, determine which receptor the laser hits first. This Mirror Reflection coding problem is a beautiful application of number theory — specifically, the least common multiple and GCM reasoning.
Microsoft, Amazon, and Google ask this because it requires translating a geometric optics problem into a number theory problem. The key insight — that the laser hitting a receptor corresponds to LCM(p, q) determining the endpoint — rewards candidates who can think beyond simulation to mathematical structure. The math, number theory, and geometry interview pattern is elegantly demonstrated.
LCM and parity reasoning. The laser effectively travels an unfolded path. After L = lcm(p, q) distance, the laser hits a corner. The number of room lengths traveled is L/p and the number of bounces is L/q. If L/p is even, the laser is at the bottom wall; if odd, at the top wall. If L/q is even, it's at the right receptor; if odd, at the left. Combine: receptor 0 (right-bottom = 0), receptor 1 (right-top), receptor 2 (left-top).
p = 3, q = 1.
Actually: L/p = 1 (odd = top), L/q = 3 (odd = right wall with receptor 1). Receptor = 1.
p = 2, q = 1: LCM=2. L/p=1 odd (top), L/q=2 even (right). Receptor 1 (top right) = 1.
Geometry problems that involve periodic reflections often reduce to LCM/GCD reasoning. The "unfolding the room" trick — imagining the laser traveling in a straight line through mirrored copies of the room — transforms reflection into linear travel. The key math: lcm(p, q) = p * q / gcd(p, q). Practice similar "billiard ball" reflection problems using the unfolding technique — it appears in Google and math-heavy interviews and requires comfort with number theory fundamentals.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Circle and Rectangle Overlapping | Medium | Solve | |
| Closest Prime Numbers in Range | Medium | Solve | |
| Prime Palindrome | Medium | Solve | |
| Rectangle Area | Medium | Solve | |
| The kth Factor of n | Medium | Solve |