Vodafone interview question

How I solved the task