Magic interview question

Ring all reduce. Only optimal solution is accepted.