How to construct a n-ary tree from it's preorder traversal if the hierarchy levels are given 

How to construct a n-ary tree from it's preorder traversal if the hierarchy levels are given 


Output:

{"INC":{"Groupname":"INC","Descript":"INC","INC-BBSR":{"INC-FORT":{"Groupname":"INC-FORT","Descript":"INC3","Valcount":0,"Hierlevel":2},"Groupname":"INC-BBSR","Descript":"INC1","INC-STPI":{"Groupname":"INC-STPI","Descript":"INC2","Valcount":0,"Hierlevel":2},"Valcount":0,"Hierlevel":1},"Valcount":0,"INC-BBL":{"Groupname":"INC-BBL","Descript":"INC4","Valcount":0,"Hierlevel":1},"INC-PUNE":{"Groupname":"INC-PUNE","Descript":"INC5","Valcount":0,"Hierlevel":1},"Hierlevel":0}}

{"INC":{"Groupname":"INC","Descript":"INC","INC-BBSR":{"INC-FORT":{"Groupname":"INC-FORT","Descript":"INC3","Valcount":0,"Hierlevel":2},"Groupname":"INC-BBSR","Descript":"INC1","INC-STPI":{"Groupname":"INC-STPI","Descript":"INC2","Valcount":0,"Hierlevel":2},"Valcount":0,"Hierlevel":1},"Valcount":0,"INC-BBL":{"Groupname":"INC-BBL","Descript":"INC4","Valcount":0,"Hierlevel":1},"INC-PUNE":{"Groupname":"INC-PUNE","Descript":"INC5","Valcount":0,"Hierlevel":1},"Hierlevel":0}}

true