Databricks | Phone | Iterating Over a Binary Tree With Constant Space
Anonymous User
15547

Given a TreeNode defined with an additional parent pointer, print all nodes of a given tree in any order using constant space. You are not allowed to modify the tree structure itself.

class TreeNode
{
  public int val;
  public TreeNode left;
  public TreeNode right;
  public TreeNode parent;
  public TreeNode(int x) { val = x; }
}
Comments (13)