Question: Problem 1 4 . Given a sorted array A [ 1 : n ] of integers and another positive integer K , you want to

Problem 14.
Given a sorted array A[1:n] of integers and another positive integer K, you want to find another
array B[1:n] such that for 1in,B[i] contains the smallestindex 1jn such that A[j]-A[i]
K. If no such index exists, then B[i] should be ?|??. For example, if A=[9,13,18,22,25,29] and K=5,
then the array B should be . To explain a bit more, B[1]=3 because A[3]-A[1]5
but A[2]-A[1]5. And, B[5]= because A[6]-A[5]5 and the array ends there.
Design an O(n)-time algorithm to solve this problem. Write a precise and succinct pseudocode.
 Problem 14. Given a sorted array A[1:n] of integers and another

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!