SPOJ FREQUENT WA

Can anyone help??

In line 58-

parent.freq1=left_child.freq1+right_child.freq1*(FREQUENT.a[mid]==FREQUENT.a[parent.start]?1:0);
parent.freq2=right_child.freq2+left_child.freq2*(FREQUENT.a[mid+1]==FREQUENT.a[parent.end]?1:0);

Dont u think it should be mid+1 in the first line and mid in the second? 
Like-

parent.freq1=left_child.freq1+right_child.freq1*(FREQUENT.a[mid+1]==FREQUENT.a[parent.start]?1:0);
parent.freq2=right_child.freq2+left_child.freq2*(FREQUENT.a[mid]==FREQUENT.a[parent.end]?1:0);

You add the right parts frequency only when the first value in right subtree is same as the first value in the parent. Likewise for the other part.

Your given code fails here:
https://ideone.com/d3zEqv
The correct answer is 5 

Do upvote if this helps :)
Happy Coding! :)
1 Like

Thanks got AC. :slight_smile: . Can you look into this??
http://discuss.codechef.com/questions/59332/spoj-gss2-wa

Umm sure..do u mind accepting my answer? :D
I would really appreciate that!