Pergunta de entrevista da empresa Microsoft

Solve the ball sorting algorithm and explain it.