Amazon Interview Question

Neetcode 150 tree traversal problem