2. (20 pts) Consider the following problem. Input: array A[1 ton] of distinct integers, and integer x Output: the rank of theinteger closest to x in AHere the rank means the minimum rank,i.e., the rank of the smallest in A is 1, that of the 2ndsmallestis 2, etc. Consequently if the element closest to x is the kthsmallest of A, the output is k. For example,
if A[1 to 4]={ 8, 1, 5, 20} and x=4, the output is 2 because theclosest to 4 is 5, having rank 2. If x=3, the output can be either1 or 2.
Design a linear time
PayPal Gateway not configured
PayPal Gateway not configured