GSA Capital interview question

Complet this LeetCode style hard quesstion