Not able to solve

Hii…
I am doing this question from codeforces…
https://codeforces.com/problemset/problem/1143/B
I am not able to solve this… or arrive at proper logic…
The Editorial also didn’t help me much…
Could you recommend me some idea…
Thanks

hello @ashishnnnnn

r u familiar with digit dp?

Noo… I am not familiar with that…

ok ,
u can learn it from here. ->link

another approach->
since we want to maximize our product . which digit we want to present most in our number?
it should be 9 right?
so basically we try to change digits to 9 .
for example
if no is 222 then 199 will give us maximum (ie iterate form right to left convert digit to 9 ).
one thing u need to take care is generated number <=n
i.e keep value of one digit with value less than given digit to make it less
for example->

253 -> (if i convert 3 to 9 ,then in that case i need to reduce other digit value(in left) to make it less than 253 right? and becuase we want to maximize product we reduce that digit vaue only by 1)
253 -> max prod of (249 or -> 199 )

I coded the second idea… and got accepted solution… Learning the Digit Dp…
Thanks :slight_smile:

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.