Implement array and tree traversal tasks | Amazon Interview Question