Pregunta de entrevista de Juniper Networks

Leetcode Medium Question which I could solve