edited by
855 views
1 1 vote

1 Answer

Best answer
1 1 vote

Sort the array.

Now do a pass through the array similar to the inner loop of selection sort as follows:

min = 0;
for(int i = 1; i< n-1; i++)
{
    if(diff(A[i], A[i+1]) < diff(A[min], A[min+1]) )
        min = i;
}

Finally A[min], A[min+1] give our required numbers.

selected by
Answer:
Position:
Show:

Related questions

5 5 votes
1 answers 1 answer
1.6k
1.6k views
balchandar reddy san asked Jan 30, 2019
1,557 views
Consider a new sorting algorithm similar to the BubbleSort algorithm, called RumbleSort. Given an array as input, RumbleSort attempts to sort the array and produces a sor...
1 1 vote
1 1 answer
1.7k
1.7k views
eyeamgj asked Jan 29, 2018
1,681 views
Given two unsorted singly-linked lists each with n distinct elements. There exists an efficient intersection algorithm, that computes and returns a new list with common e...
3 3 votes
1 answers 1 answer
1.2k
1.2k views
mohitbawankar asked Nov 2, 2017
1,177 views
Consider two arrays A[] and B[],if arrays A is in increasing order and array B is in decreasing order is input to join a algorithm. the output is an array C[1......2n] wh...
8 8 votes
6 6 answers
3.8k
3.8k views
Arjun asked Feb 27, 2025
3,806 views
Suppose that insertion sort is applied to the array $[1,3,5,7,9,11, x, 15,13]$ and it takes exactly two swaps to sort the array. Select all possible values of $x$.$10$$12...