Pergunta de entrevista da empresa Shopee

Write a function that iterates a tree and produce a string of all the components in the desired format.