Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

In-Order Traversal Implementation

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is In-Order Traversal Implementation. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Cloudera Manager represents hierarchical configuration data with tree structures. Given the root of a binary tree, return its node values in in-order sequence: visit the left subtree, then the current node, then the right subtree.

Implement the traversal iteratively using an explicit stack. The input is provided as a TreeNode object whose fields are val, left, and right. The evaluation harness constructs the tree from a level-order array, where null represents a missing child. Return a Python list of node values.

Constraints

  • 0 <= number of nodes <= 10^4
  • -10^5 <= node.val <= 10^5
  • The input is a binary tree of TreeNode objects
  • The tree must not be modified

Function Signature

def inorder_traversal(root):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output