Pergunta de entrevista da empresa Capital One

How would you refactor this code? And it was literally just consolidating if statements into while loops and moving them around.