Pregunta de entrevista de Net Driven

asked me to solve a coding problem.