Can you explain what part is not clear?
Can anyone help not albe to find where code fails.Did almost same as editorialist @likecs.
link-https://www.codechef.com/viewsolution/19046621
@atharva_sarage, did you consider the case that the tree may not be perfectly balanced?
ie) left child = leaf and right a tree or vice versa. The condition still needs to be satisfied even if one side is a tree.
@tamiliit : Thank you so much for pointing me in the right direction. I was swapping the wrong values, I had to swap the two intervals, so the start and end would become lr and rl instead of rr and ll. It was really silly of me but since you went through my code and suggested to me exactly what was needed, I got it right. Thanks again. good night.
Can someone please explain setterâs solution? I am not able to understand the meaning of statement :
if (kol[p] != mx[p] - mn[p] + 1) ok = false;
TIA.
@rj25, For correct implementation of top-down approach, an initial traversal of the tree to calculate minimum and maximum in subtree is required which is essentially a bottom-up approach. A top-down approach can then be applied later as swaps are independent at each level.
@atharva_sarage, you code is wrong here
(tree[vec[maxheight][i]].root!=1 && tree[vec[maxheight][i+1]].root!=1)
This will be an issue when one side is leaf and other side is not.
Hey, I still couldnât understand the problem statement. How the strings are LL,RL,RR and how the input is converted to a binary tree. Can anyone please explain it properly, that would be really helpful !
could not understand how to implement from editorial but code was simple. Was a good editorial combined with implementation code provided.
Thanks.
The question is interesting
@likecs In question the constraints has N>=2 but if N=2 then its impossible to build the tree because in question there is mentioned that ânon-leaf: has exactly two sons â a left son and a right sonâ,for root is doesnât satisfy, am i right to point it out?
Still its a interesting question