ALL test cases not working

hello @dhruv.mahajan.mait

in the question they have asked to avoid leading 0s.

for example->
for input 999, output should be 900 (we cant convert 1st 9 to 0 becuase that will produce leading zero)

but urs code will print 0

read a number as string (say s) .
if left most character is ‘9’

  • then leave the leftmost character as it is and for other characters simpl replace s[i] with min(s[i],‘9’-s[i])

else:

  • for each i replace s[i] with min(s[i],‘9’-s[i])

print s

#include<bits/stdc++.h>

using namespace std;

int main() {

    string n;

    cin>>n;

    int start=0;

    if(n[0]=='9')

       start=1;

    for(int i=start;i<n.length();i++){

            char c='9'-n[i]+'0';

            n[i]=min(n[i],c );

    }

    cout<<n;

    return 0;

}

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.