Pergunta de entrevista da empresa TikTok

Task from the leetcode, average