binary search implemented as Josef's interview question