Pregunta de entrevista de IBM

Asked me to solve the same question i had solved in the coding round.