Pergunta de entrevista da empresa Apple

How would you code a solution