Leetcode problem same as in this video

the problem is :


my solution for this is :

can you please check and explain me what the error that is coming here is?
i have serialised the tree in preorder fashion and put a # wherever there is a NULL. my serialise function is running fine, there is a problem with deseialise which is the same as the buildtree in this video. plz run it on leetcode and explain me the error.

your function is correct
the problem is
for a tree of height h
your solution takes 2^(h+1).2 time
which is why this is failing
u can use this


this another good solution

but it is showing compilation error and not time limit exceeded

hey, i checked, it was showing tle to me, i mean ur code


this code, it is ur code only, my submission for this fails on test case 45/48
due to tle

u can try refreshing the leetcode page

this is the error that it is showing me

string temp = “”;
while(i<l and data[i]!=’ '){
temp += data[i] ;
i++ ;
}
i++ ;
if(temp.size()!=0)
dta.push_back(temp) ;

the difference is here, in ur function some garbage must have been pushed

can you please tell me a little bit more about how it’s time complexity is 2^(h+1).2?

in my own code i just passed the dta vector by reference in the buildtree function and it is working now. please explain how is its time complexity exponential, i am just doing a DFS in preorder traversal?

traversing all the nodes and their children in any complete tree is 2^(h+1)
and u were traversing them twice so it’s 2^(h+1).2

is 2^(h+1) the same as O(N) ?

for a complete tree, yes. but not for all trees