Pregunta de entrevista de TikTok

Leetcode question on maximizing a sequence in an array