BitTitan interview question

a coding question using dynamic programming