Pergunta de entrevista da empresa TikTok

Leetcode question on maximizing a sequence in an array