Solution to the question posted