Pergunta de entrevista da empresa TMRW

Asked to solve dsa question