Even Financial interview question

Solving a standard Leetcode medium/hard type question.