Capital One interview question

Typical medium level algorithmic leetcode type problems.