Problem code: STACKS
I’m getting compile time error ,all test cases works fine .
#include<iostream>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,i,j,count=0,size;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){ //ARRARY1 INPUT
cin>>arr[i];
}
int arr2[n];
arr2[0]=arr[0];
bool check=false;
//LOGIC
for( i=0 ,j=1;i<j, j<n;i++, j++){
check=false;
if(arr[j]>arr2[i]){
count++;
arr2[count]=arr[j];
//cout<<arr2[count]<<"\n";
}else
{
for(int k=0;k<=count;k++){ //runs till count
if(arr[j] <arr2[k]){
arr2[k]=arr[j];
check=true;
i--;
break;
} if(check) break;
}
}
}
int c = count+1;
cout<<c<<"\t";
for(i=0;i<=count;i++){
cout<<arr2[i]<<" ";
}
cout<<endl;
}