Pergunta de entrevista da empresa Tata Consultancy Services

One coding question about the logic