Nahid8195

Longest Squence

Aug 9th, 2021
1,082
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7. int arr[]={5,4,-3,1,7,2,3,-20};
  8. int n=sizeof(arr)/sizeof(arr[0]);
  9. vector<int> v[n];
  10. int i,j=0;
  11. v[0].push_back(arr[0]);
  12. for(i=1;i<n;i++){
  13. if(arr[i]>arr[i-1]){
  14. v[j].push_back(arr[i]);
  15. }
  16. else{
  17. j++;
  18. v[j].push_back(arr[i]);
  19. }
  20. }
  21.  
  22. int bigsize=0,bigindex,h;
  23. for(i=0;i<=j;i++){
  24. h=v[i].size();
  25. if(h>bigsize){
  26. bigsize=h;
  27. bigindex=i;
  28. }
  29. }
  30. printf("Length : %d\n",bigsize);
  31. printf("largest sequence: ");
  32.  
  33. for(i=0;i<v[bigindex].size();i++){
  34. printf("%d ",v[bigindex][i]);
  35. }
  36. }
RAW Paste Data