Domanda di colloquio di TikTok

Merge two lowest duplicates in an array until none left.