Pregunta de entrevista de YLD

Technical question was building a algorithm that is roughtly medium on leetcode