Compass interview question

A fairly difficult graph traversal problem, not ideal for JS