solution with explanations