Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Binary Tree Preorder Traversal

Medium
MediumCodingRecursionStackTreesAsked 1 times

Problem

Given the root of a binary tree, return the values in pre-order traversal: visit the current node, then the left subtree, then the right subtree. Implement the traversal and handle an empty tree correctly.

Constraints

  • 0 <= number of nodes <= 10^4
  • -10^4 <= Node.val <= 10^4
  • The tree may be empty
Practicing as: Mobile Engineer interview at Bell

Hi, I'll play your Bell interviewer for the Mobile Engineer role. Answer the question above like we're in the room, and I'll respond the way a real interviewer would.

Take this as a live interview session →

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
def solve(rows):
    counts = {}
    for row in rows:
        ...
    return result
Sign up to unlock solutions
Bell Mobile Engineer Interview QuestionsTop 50 Stack Interview QuestionsTop 50 Trees Interview QuestionsBell Interview Questions
Next questions
SalesforceBinary Tree Inorder TraversalEasyFujitsuBinary Tree Level Order TraversalEasyPalo Alto NetworksBinary Tree Right Side ViewMedium