OpenText Interview Question

Two coding round question asked. Basic problem