I worked as a mechanical engineer for two years before learning programming. For my first practice, I picked an easy coding question on purpose: two…