binary search to avoid map function