why it is showing time limit error
Chewbacca number
hello @lovely
u r never updating ur y.
ie ur y will never become 0 , due to which the loop will keep running and hence the tle

btw u can easily solve ths proble using stirng.
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;
}
1 Like
i updated my previous code now.and only 1test case is not getting passed.can u check why.
check now->
1 Like
thanks it get passed now.
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.