Pergunta de entrevista da empresa Net Driven

asked me to solve a coding problem.