Microsoft interview question

Array question based on simple maths DFS graph question