SORT15


TEST CASE 1 

INPUT
2
11
100 56 5 6 102 58 101 57 7 103 5
3
10 100 105
OUTPUT
4
3

TEST CASE 2 

INPUT
5
12
12 23 85 11 65 22 87 24 10 86 64 63
5
1 5 3 2 6
7
6 8 1 7 2 5 4
10
45 21 74 44 72 20 4 73 5 46
8
4 2 9 5 3 7 8 1 
OUTPUT
4
2
2
4
2

#include <stdio.h>
int i,count=0,j;
void sort(int a[],int n)
{
  int i,j,temp;
  for(i=0;i<n-1;i++)
  {
    for(j=0;j<n-i-1;j++)
    {
      if(a[j]>a[j+1])
      {
        temp=a[j];
        a[j]=a[j+1];
        a[j+1]=temp;
      }
    }
  }


}
void noofsubset(int a[],int n)
{
  sort(a,n);
  for(i=0;i<n;i++)
  {
    if(a[i]+1!=a[i+1])
      count++;
  }
  printf("%d\n",count);
  count=0;
}
int main()
{
  int a[30],n;
  int t;
  scanf("%d",&t);
  for(j=0;j<t;j++)
  {
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  noofsubset(a,n);
  }
  return 0;
}

Comments

  1. Suppose the input is as follows :
    1
    3
    9 12 14
    then it will give 3 as output which is totally wrong.
    Though there are 3 subsets but none of them have consecutive numbers

    ReplyDelete

Post a Comment

Popular posts from this blog

AR1

SER12

AR15