Juniper Networks Interview Question

Leetcode Medium Question which I could solve