Pregunta de entrevista de Block

Leetcode question of Hard difficulty.