GATE | Gate IT 2005 | Question 58
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0.
i = 0;
j = 1;
while (j < n )
{
if (E) j++;
else if (a[j] - a[i] == S) break ;
else i++;
}
if (j < n)
printf ( "yes" )
else
printf ( "no" );
|
Choose the correct expression for E.
(A) a[j] – a[i] > S
(B) a[j] – a[i] < S
(C) a[i] – a[j] < S
(D) a[i] – a[j] > S
Answer: (B)
Explanation: Please see the link below for full explanation
https://www.geeksforgeeks.org/find-a-pair-with-the-given-difference/
Quiz of this Question
Last Updated :
28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...