Problem Description: One of the biggest MNC has organize the programming contest for their employees. They are providing some integers and find out the longest subarray where the absolute difference between any two elements is less than or equal to 1 Constraints: 2 ≤ n ≤ 100 0 < a[i] < 100 Input Format: The first line contains a single integer 'n', the size of the array 'a'. The second line contains 'n' space-separated integers, each an a[i].
C Program


#include<stdio.h>

#include<stdlib.h>

void insertionSort(int *p,int n)

{

int i,key,j;

for(i=1;i<n;i++)

{

key=p[i];

j=i-1;

while(j>=0 && p[j]>key)

{

p[j+1]=p[j];

j--;

}

p[j+1]=key;

}

}

int main()

{

int n;

scanf("%d",&n);

int *arr;

arr=(int *)malloc(n*sizeof(int));

for(int i=0;i<n;i++)

scanf("%d",&arr[i]);

insertionSort(arr,n);

int max=0;

for(int i=0;i<n;i++)

{

int count=0;

for(int j=i;j<n;j++)

{

if(arr[j]-arr[i]<=1)

count++;

else

break;

}

if(count>max)

max=count;

}

printf("%d",max);

return 0;

}