You are viewing a single comment's thread. Return to all comments →
Took me some time to realise the output of 5 1 2 is 10007 10009 instead of 10007 10037 (Python, it gave wrong answer for Test #3 and #10).
5 1 2
Was trying to save time by returning the first plausible result from digit replacement generated by looping through digits from 0 to 9, and it turns out that way it's not necessarily the minimum result.
Eventually I computed all plausible results from all digit replacement and its corresponding permutations. I would say it's too ugly to my taste.
EDIT: Made use of generator combining permutations with deque() to yield the next smallest replacement position, so it does not have to generate the whole thing in advance. Sounds simple, troublesome to implement. The slowest time for me is 4.74s for #18. Previous version took almost 8s...