Pregunta de entrevista de OpenText

Two coding round question asked. Basic problem