← 返回 doordash 的题目列表Bottom-Up Level Order Traversal of Menu Tree Items
类型:online_judge
doordash
Given a menu represented as a tree structure, design an algorithm to extract the names of the items and organize them into a list of item names in the order of their levels. Assume the nodes of the tree are represented as {'name': 'item name', 'children': []}. You need to output the list of items for each level, with the bottom level first and the root last.
Example
Input
{"name": "Root", "children": [{"name": "Appetizer", "children": [{"name": "Wings", "children": []}, {"name": "Fries", "children": []}]}, {"name": "Main", "children": [{"name": "Steak", "children": []}, {"name": "Salad", "children": []}]}]}