TESTCASE # 1 : timelimit (Time: 5.97 s)
What does this output mean?
Hello,
It must be Time Limit Exceeded error.
If you’ll send your code that is producing this output, then it would be easier for me to analyse your doubt.
#include
using namespace std;
int main()
{
int arr[100];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int lo=0;
int hi=n-1;
int mid=0;
while(mid<=hi)
{
if(arr[mid]==1)
{
mid++;
}
else if(arr[mid]==2)
{
swap(arr[mid],arr[hi]);
hi–;
}
else
{
swap(arr[mid],arr[lo]);
lo++;
mid++;
}
}
for(int i=0;i<n;i++)
{
cout<<arr[i]<<endl;
}
return 0;
}
@angivanshikaangi constraints given in the question is 10^6 but you given 100 so increase the size of array.
What i am getting as output after running your code is run-error.
There is an obvious reason for the same.
i.e. how do you that the user will enter only 100 elements in the array?
Solution:
int n;
cin>>n;
int arr[n];
It will remove the above issue. But, you’ll face the problem of wrong output as you are considering that the elements can only be 0,1 and 2.
But this question allows the user to enter any number as array elements.
Please, correct your code.
Hope, this would help.
Give a like, if you are satisfied.