
In a Meta mobile app such as Facebook or Instagram, UI debugging often requires inspecting the full view tree from a root view. Given the root of a view hierarchy, return a formatted list of strings representing the entire hierarchy in top-down order, with indentation showing parent-child relationships.
Each view has a name string and a list of children. Write a function that traverses the hierarchy and returns one string per view. The root should have no indentation, its children should be prefixed with two spaces, grandchildren with four spaces, and so on.
root, a view node object or Nonename: stringchildren: list of child view nodesExample 1
Input:
root = View("Root", [View("Header"), View("Body")])
Output:
["Root", " Header", " Body"]
Explanation: Header and Body are direct children of Root, so each is indented by two spaces.
Example 2
Input:
root = View("Root", [View("Feed", [View("StoryTray"), View("Composer")])])
Output:
["Root", " Feed", " StoryTray", " Composer"]
Explanation: StoryTray and Composer are grandchildren of Root, so they use four spaces.
[0, 10^4][1, 100]0 to 100 children