Not able pass test 3 and 4(message showing correct)

#include
using namespace std;
int main() {
int n,rem,i,k=0;
cin>>n;
int a[100];
i=0;

while(n!=0)
{
	rem=n%10;
	k++;
	if(9-rem<rem)
	{
		a[i]=9-rem;
		i++;
	}
	else{
	a[i]=rem;
	i++;
	}
	n=n/10;
}
for(i=k-1;i>=k-1;i--)
{
	if(a[i]==0)
	a[i]=9;
}
for(i=k-1;i>=0;i--)
cout<<a[i];

	return 0;

}

Check the constraints in the question.
The number can be up to 10^18 but an array of size greater that 10^5 will give an error. So try to solve this question without using an array. Use long long int data type inplace of int. As int cannot store numbers >10^9

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.