binary search: sort array with duplicates