fork(3) download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #define gc getchar_unlocked
  4. #define pc putchar_unlocked
  5. inline int scan(){register int n=0,c=gc();while(c<'0'||c>'9')c=gc();while(c<='9'&&c>='0')n=(n<<1)+(n<<3)+c-'0',c=gc();return n;}
  6. bool c[100001]={0};
  7.  
  8. int findLongestsequence(int a, int count){
  9. int st=a,i,j;
  10. a++;
  11. if(c[a]==1){return(findLongestsequence(a,++count));}
  12. return count;
  13. }//findLongestsequence
  14.  
  15. int main(void){
  16. int i=0,j,t,n,st,len,count=1,maxcount=1,maxseq=-1;
  17. len=scan();
  18. j=len;
  19. int a[len];
  20.  
  21. while(j--){
  22. a[i]=scan();
  23. c[a[i]]=1; //creating hash with value pair same
  24. i++;
  25. }
  26. printf("Entered String :");
  27. for(i=0;i<len;i++){printf("%d ",a[i]);}
  28. for(i=0;i<len;i++){
  29.  
  30. count = findLongestsequence(a[i],count);
  31. if(count > maxcount ){
  32. maxcount= count;
  33. maxseq = a[i] ;
  34. }
  35. count=1;
  36.  
  37. }
  38. //printf("\nSt and Len : %d & %d\n",maxseq,maxcount);
  39. printf("\nMaximum Consequitve string ");
  40. while(maxcount--) printf("%d ",maxseq++);
  41. return 0;
  42.  
  43. }
Success #stdin #stdout 0s 2392KB
stdin
19 10 21 45 22 7 2 67 19 13 45 12 11 18 16 17 100 201 20 101
stdout
Entered String :10 21 45 22 7 2 67 19 13 45 12 11 18 16 17 100 201 20 101 
Maximum Consequitve string 16 17 18 19 20 21 22