TikTok interview question

Leetcode question on maximizing a sequence in an array