There are a number of different ways to tackle this problem. The solution I gave comes from a series of…