Microsoft interview question

Easy math question and graph traversal.