Pregunta de entrevista de Amazon

Leetcode level problem very difficult