1 comment

[ 3.0 ms ] story [ 138 ms ] thread
It isn't true that closed intervals can never be empty. expanding the definition of the interval is the solution. a closed interval is the intersection of 2 "rays"

x in [a,b] iff a <= x and x <=b

so any interval where a>b is empty. which is what you are testing for in the half open case, i!=j is testing for "empty array"

so you only need to change the while condition to i<=j and then you would see the termination condition wouldn't fail in the first if within the while loop

you change the semantics of your test and so it broke

half open is still better, but its not for this reason.