
In a Meta mobile app such as Facebook or Instagram, a screen can be represented as a tree of views. Given the root view, return the entire view hierarchy as a list of formatted strings, one per line, using indentation to show parent-child relationships.
Implement a function that traverses the tree in preorder: visit the current view first, then recursively visit its children from left to right. Each output line should contain depth levels of indentation, where each level is two spaces, followed by the view's name.
root, a dictionary representing the root view, or null{"name": string, "children": [view, view, ...]}Example 1
Input:
root = {"name": "Screen", "children": [{"name": "Header", "children": []}, {"name": "Feed", "children": [{"name": "StoryTray", "children": []}]}]}
Output:
["Screen", " Header", " Feed", " StoryTray"]
Explanation: Header and Feed are children of Screen, and StoryTray is a child of Feed.
Example 2
Input:
root = null
Output:
[]
Explanation: An empty hierarchy produces no lines.
0 <= number of views <= 10^50 <= number of children per view <= 10^41 <= len(name) <= 100