Segmentation fault for static declaration


can anyone explain why usage of preorder index as static variable gives us segmentation fault??
solve the problem by passing preorder index as reference.


because your code is being tested on a number of test cases and if you use preorder index as static it will be same for all the test cases which will give error.