In this algorithm, first we declare an array of int a to store array elements and the variable i and j to run the loop, n for getting the no. of elements in the array.
Res is for storing the result. We Read variable n and array a. We run for loop i=0 to i=n and inside that another loop for which will run from j=i to j=n.
We will check abs(a[i]-a[j]>res), it means that when we are subtracting a-a then a-a ,a-a ,a-a....a-a[n].So we can see that when i=0 j will run from 0 to n then i=1 j will run from 1 to n. Likewise it will happen for all the numbers. So we are checking the subtraction of two elements and it's absolute value whether is greater than res or not. If it is greater it will get store in res otherwise it will pass.
Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once.