Shortest Path for a Bug in a Cubic Room
Shortest path across a cube is a medium quant interview question on Brain Teasers.
This brain teaser asks for the minimal crawling route a bug can take between two opposite corners of a cube-shaped room, under the restriction that it must stay on the surfaces. The candidate has to reason about how to traverse multiple faces of a cube while never entering its interior, and how the "farthest corner" is reached when direct straight-line travel through space is forbidden. The twist lies in realizing that the naïve paths along edges or obvious face diagonals are not necessarily optimal, and that a less intuitive route across several faces can be shorter.
Solving it leans on geometric visualization, spatial reasoning, and the idea of flattening three-dimensional surfaces into a plane. The interviewer is looking for recognition that the problem becomes simpler when the cube's faces are unfolded into a net and the two corners are connected by a straight segment in that net. Strong answers clearly articulate why this transformation preserves surface distances, compare plausible nets, and justify which configuration yields the truly shortest path.
What it tests
Whenever a shortest path is constrained to the surfaces of a polyhedron, the problem reduces to finding the geodesic on that surface. For convex polyhedra like cubes, this geodesic can always be represented as a straight line on some unfolded (net) version of the surfaces, because unfolding preserves distances along the surfaces. The key is that the shortest surface path between two points is the straight line connecting them in an appropriate net, even if that path crosses multiple faces. This principle holds because the act of unfolding does not stretch or shrink the surfaces—so the straight line in the net corresponds to the minimal surface path when the polyhedron is refolded. The challenge is to find the right unfolding that places both points on the same plane, minimizing the straight-line distance.
Practise this question with written feedback, or hear it in a spoken mock interview.
Get started free