Quote Originally Posted by _uj
Well, I didn't suggest a BST to be built In my reply #15 I suggested an O(log N) solution based on two slightly modified standard binary searches.
oh okay my bad, you did not suggest a BST ..

but its good the OP can now have some options on how to solve the problem ..