Skip to main content

Tree Node

EasyPremium

Given a binary tree, identify which nodes are leaf nodes, root nodes or inner nodes.

  • Leaf nodes: A node with no children
  • Root nodes: A node with no parent
  • Inner nodes: A node with both children and parent nodes

You are given the following table tree_node_table:

idp_id
integerinteger

where p_id is the id of the parent node. Your output should contain the following columns: id, node_types (’Root’, ‘Inner’, ‘Leaf’).