Accenture Interview Question

Codiing question from codility and leat code