but was uanble to figure out as why- ““int getMid(int s, int e) { return s + (e -s)/2; }””.
Here the getMid funct should be returning ((s+e)/2) and not the above one.Plz help unable to figure out.
The comments already explain that… If the current segment is inside of our query range just return its value… The best way to solve segment trees is to try and solve some problems with it… The link you’re following is great but the code is way too big to start with… I suggest you to read the topcoder tutorial too: http://www.topcoder.com/tc?d1=tutorials&d2=lowestCommonAncestor&module=Static#Segment_Trees