Need HELP IN "REVERSE MAXIMIZATION" problem of may lunchtime

My code is passing for all test case but not in one and i can’t find my mistake…please help me…
here is the code
t=int(input())
while(t>0):
n=input()
i=0
while(n[i]==‘0’):
i+=1
n=n[i:]
k=len(n)
a=n[0]+‘9’(k-1)
if(n==a):
print(a)
else:
if(n[0]==‘1’):
i=1
while(i<k and n[i]==‘0’):
i+=1
if(i>=k-1):
print(n)
else:
a=n[:i+1]+‘9’
(k-i-1)
if(n==a):
print(a)
else:
a=n[:i]+str(int(n[i])-1)+‘9’(k-i-1)
print(a)
else:
a=str(int(n[0])-1)+‘9’
(k-1)
print(a)
t=t-1

Try the testcase:- 1000987 :slight_smile:

1 Like

here is the answer
1

1000987
1000899

Your code gives wrong answer for n=100 :slight_smile:

Whats wrong with this code it is working correcly for upto 100000
in dev c++?
https://www.codechef.com/viewsolution/24386807

here is the answer for 100
1

100
100

Hey try your code for 1100 @princekmeena

which is wrong, answer should be 99 lol

answer for 100 is 99, his code gives 100, reverse 100 and you’ll get “1”

1 Like

yeah just missed it …what a great mistake!!!

1 Like

That reply was meant for @princekmeena :sweat_smile::sweat_smile:

Actually your all answers are printing in reverse. :sweat_smile:
For 19 its printing 91.

1 Like

and my reply was meant for you :stuck_out_tongue: as his code gives gives correct answer for 1100 :stuck_out_tongue:

Thank you what a silly mistake i did

It’s giving 9901, which is incorrect…

Its correct 1100 = 1099 + 1
put 1099
1099 is correct actually
but 9901 is not

I am not talking about your code :stuck_out_tongue: