Home /
Expert Answers /
Computer Science /
solve-in-c-problem-1-upper-and-lower-bound-description-given-a-sorted-array-a-of-size-ma-pa256
(Solved):
Solve in C++
#Problem 1: Upper and Lower Bound Description: Given a sorted array A of size \( \ma ...
Solve in C++
#Problem 1: Upper and Lower Bound Description: Given a sorted array A of size \( \mathrm{N} \) and a search value \( \mathrm{S} \), you have to find the upper and lower bound value for S. In the first line, you will be given \( \mathrm{N} \) and \( \mathrm{S} \). In the second line, you will be given \( \mathrm{N} \) values denoting the sorted array. You have to print the upper and lower bound respectively with a single blank space. Keep a new line character after each output. Print the answer using 0 based indexing. Upper Bound: The index of the smallest value in the sorted array which is greater than S. For repeating such values consider the largest or the right-most index. If the largest value in the array is smaller than \( \mathrm{S} \). Then the upper bound is the sizo of the array. Lower Bound: The index of the largest value in the sorted array which is smaller or equal to S. For repeating such values consider the smallest or the left-most index. If \( \mathrm{S} \) is smaller than the smallest value In the array, consider the lower bound as 0 . Limits: \[ 1<=|\mathrm{A}|<=100000 \] Test Cases: - First solve for non repeating elements - Then consider the solution for repeating elements - Try to write code using separate functions