Accenture interview question

Codiing question from codility and leat code