Pergunta de entrevista da empresa World Wide Technology

Algorithm question. Solve and write pseudo code on the white board.