[Community Puzzle] Closest Number

https://www.codingame.com/training/hard/closest-number

Send your feedback or ask for help here!

Created by @Nagrarok,validated by @Stilgart,@jitsch and @Fireball0923.
If you have any issues, feel free to ping them.

any hint to work with big numbers?
I am using the ruby permutation method but it times out on the big numbers

This puzzle is indeed about string manipulation. But there is no need for permutations.

Look closely at the solutions for the given tests and you might see a property that decreases a lot the number of cases to consider.

In my opinion simple permutation will run into a problem on big numbers because the number of permutations will be (n!). For a number with “just” 12 diggits there are 12! = 479,001,600 possibilities.

Keep this in mind.

Can we have some extra ‘leading with zero’ testcases?
I seem to pass all the tests, except from the extra testcase of ‘solution leading with zeros’ after submission.

Thank you!