3

We can simplify this quite a bit. At a high level, note that all you are doing is: Converting each digit of the input to an array of possible neighbors. Now you have an array of neighbor arrays. The answer is simply the cartesian cross product of those neighbor arrays. Sort them. Turn the into back into strings. The cartesian cross-product is a simple ...


Only top voted, non community-wiki answers of a minimum length are eligible