Microsoft interview question

Solve the ball sorting algorithm and explain it.