The solution is written with detailed explanation.