Domanda di colloquio di TikTok

Leetcode question on maximizing a sequence in an array