Hello everyone, I was trying to solve this problem, 1765N - Number Reduction. I wrote a code and its logic is same as the editorial but rather than finding from digit '0' to '9' which is occurs first in the next 'k+1' elements in the number from left to right, I just searched the minimum among the 'k+1'.
My code works on almost all testcases except when the input is increasing, like n=1337 and k=2. Answer should be 13 but mine gives garbage value.
Here is my code,
I saw authors code solutions using stack to keep the smallest elements. Can someone provide me some corrections in my code, or will i need to implement stack solution?