Pregunta de entrevista de Squarepoint Capital

leetcode medium question (<1400cf difficulty)