Pregunta de entrevista de Amazon

The asked me a leetcode hard type problem