Binary Search on an Ascending Array
MediumRead an integer N, then N integers in ascending order into an array, then a key. Verify the order first: if any value is smaller than the one before it, print array is not in ascending order and return 1. Then search with a lo, hi, mid window, computing mid as lo + (hi - lo) / 2 and moving lo to mid + 1 or hi to mid - 1, and print key 23 found at index 5 with the zero-based index, or key 7 not found. N must be between 1 and 100; otherwise print N must be between 1 and 100 and return 1. If N, any value, or the key cannot be read, print invalid input and return 1.
Success Criteria
Your code must pass 10 test case(s) to complete this exercise. 3 hint(s) are available if you need help.
How did you find this exercise?
Your rating helps us improve the content.
Sign in to track your progress
You can work on exercises as a guest, but sign in to track your progress and save your submissions.