Pergunta de entrevista da empresa OpenText

Two coding round question asked. Basic problem