Write a binary search function that works iteratively, taking a target int, array of ints, and size of the array, returning the index of the found item, or -1. — int binary_search(int target, int numbers[], int size) { int low = 0; int high = size - 1; int mid = 0; while (low <= high) { mid = (high + low) / 2; if (target > numbers[mid]) { low = mid + 1; } else if (target < numbers[mid]) { high = mid - 1; } else { return mid; } } return -1; }
G
1.2K
Google Interview
This flashcard deck made by jwasham contains knowledge about google interview. For more details, please follow https://github.com/jwasham/google-interview-university