Cisco interview question

a leet code intermediate question