Pergunta de entrevista da empresa TikTok

Merge two lowest duplicates in an array until none left.