101
0/304
Loading content...
A platform stores a rooted binary hierarchy in the table Tree.
Schema:
Every row is one node in the same valid tree.
Your task is to label each node with exactly one category:
Return the result with exactly two columns:
Sort by N in ascending order.
Supported submission environments:
Tree:
| N | P |
|---|------|
| 1 | 2 |
| 3 | 2 |
| 6 | 8 |
| 9 | 8 |
| 2 | 5 |
| 8 | 5 |
| 5 | null |[
{"N":1,"Type":"Leaf"},
{"N":2,"Type":"Inner"},
{"N":3,"Type":"Leaf"},
{"N":5,"Type":"Root"},
{"N":6,"Type":"Leaf"},
{"N":8,"Type":"Inner"},
{"N":9,"Type":"Leaf"}
]Node 5 is the only root. Nodes 2 and 8 each have at least one child, so they are Inner. Nodes 1, 3, 6, and 9 have no children, so they are Leaf.
Tree:
| N | P |
|----|------|
| 42 | null |[
{"N":42,"Type":"Root"}
]A one-node tree contains only the root.
Tree:
| N | P |
|----|------|
| 50 | 20 |
| 70 | 50 |
| 10 | null |
| 20 | 10 |
| 30 | 10 |
| 40 | 20 |[
{"N":10,"Type":"Root"},
{"N":20,"Type":"Inner"},
{"N":30,"Type":"Leaf"},
{"N":40,"Type":"Leaf"},
{"N":50,"Type":"Inner"},
{"N":70,"Type":"Leaf"}
]Node 10 has no parent and is Root. Nodes 20 and 50 each appear as parents, so they are Inner. Nodes 30, 40, and 70 are non-root nodes with no children, so they are Leaf.
Constraints