Binary Tree Preorder Traversal Problem

Binary Tree Preorder Traversal Problem — ExecCode Medium DSA Practice

Solve the Binary Tree Preorder Traversal problem on ExecCode. Free online medium DSA practice in Tree. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description Given the root of a binary tree, return the preorder traversal of its nodes' values. Constraints The number of nodes in the tree is in the range [0, 100]. -100 <= Node.val <= 100 Notes Follow up: Recursive solution is trivial, could you do it iteratively?

Examples

Input {"data": "1\n2\n3\n#\n#\n#\n#"}; Output 1 2 3. Input {"data": "1\n#\n2\n3\n#\n#\n#"}; Output 1 2 3. Input {"data": "1\n2\n#\n4\n#\n#\n3\n#\n#"}; Output 1 2 4 3

Constraints

The number of nodes in the tree is in the range [0, 100]. -100 <= Node.val <= 100

Practice Binary Tree Preorder Traversal free on ExecCode. Browse DSA problems, topic map, and placement guides.