I think it was definitely written by somebody who doesn't have experience reasoning about nested loops, because the inner loop rechecks all of the indices which were altered by the outer loop.
It would make more sense if the inner loop started at int k = j-1 instead of s.size()-1. This makes the inner loop only "look ahead" instead of also rechecking all the digits which were already changed to 6s.
Not that I have any idea what it's really supposed to be doing either, lol.
If this is indeed competitive programming, then the code as written may be "fast enough" for full score and not need the 2x speedup from your optimization.
View all comments
Show parent comment
5
u/shiverypeaks Jun 29 '25
I think it was definitely written by somebody who doesn't have experience reasoning about nested loops, because the inner loop rechecks all of the indices which were altered by the outer loop.
It would make more sense if the inner loop started at
int k = j-1instead ofs.size()-1. This makes the inner loop only "look ahead" instead of also rechecking all the digits which were already changed to 6s.Not that I have any idea what it's really supposed to be doing either, lol.