Domanda di colloquio di Palo Alto Networks

Two questions, medium difficulty, can probably be found in Leetcode. A question about trees