Magic Interview Question

Ring all reduce. Only optimal solution is accepted.