I wasnt able to give him a working solution
Input - > 1{first 2{second 1{third} fourth} fifth} 3{sixth} Output -> first second third fourth second third fourth fifth sixth sixth sixth