Pregunta de entrevista de Applied Intuition

Coding question with hard LC difficulty