SOrting in linear time

I did same as in hint video not able to pass second testcase…

#include
using namespace std;

int main()
{
int a[10],n;

cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i];
}

int l=0,mid=0,h=n-1;

while(mid<=h){
    if(a[mid]==0){
        swap(a[l],a[mid]);
        l++;
        mid++;
    }
    else if(a[mid==1]){
        mid++;
    }
    else{
        swap(a[mid],a[h]);
        h--;
    }
}

for(int i=0;i<n;i++){
    cout<<a[i]<<endl;
}


return 0;

}

2 problems:

  1. you took very small array size = 10… but array can be as large as 1000000…
    so declare int a[1000000];
  2. else if(a[mid==1]){
    mid++;
    }
    check condition: it should be a[mid]==1.

please rate and resolve if satisfied.
thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.