Pregunta de entrevista de Sulopa Solutions

they ask me to solve the problem on JavaScript