diff --git a/sort_search_problems/first_occurrence_binary_search.cpp b/sort_search_problems/first_occurrence_binary_search.cpp index 9778279..21360ad 100644 --- a/sort_search_problems/first_occurrence_binary_search.cpp +++ b/sort_search_problems/first_occurrence_binary_search.cpp @@ -13,7 +13,7 @@ int low = 0; int firstOccurrance = -1; while ( low <= high ) { - int mid = (high + low) / 2; + int mid = low + (high - low)/2; //avoiding overflow if ( key < vec[mid] ) { high = mid - 1; } else if ( key > vec[mid]) {