Domanda di colloquio di Applied Intuition

Coding question with hard LC difficulty