Beautiful reminder that I should brush up on my regex.
There are no random tests.
elements[dest++] = val; 👎🏻
elements[dest++] = val;
Good call. I've also added an easy way to print the list so people can debug it more easily.
Thank You! Very nice kata, looking forward to more of such DS katas.
I think the better solution is to do it in place, but it is not important. The only thing that is not allowed (per the way the Node is coded) you cannot swap values around.
you do not provide an important information: can we mutate the linked list or do we have to provide a fresh one?
I hesitated with an issue, but well... Let's do this with a suggestion:
You should implement the toString method for the class Node, so taht the assertion message will be meaningful.
these are two different tests. And the first one expect effectively false. And your code failed on the seoncd one, not the first.
Note that none of the strings you put there do match excatly any in the test cases (that I can see since I already solved the kata). So I suggest you review your code and moreover the place where you put your print statment.
This comment is hidden because it contains spoiler information about the solution
Nice kata, thanks. :-) As Java doesn't have tail recursion optimization and you really wouldn't want a recursive solution to make it into production it would be good to either add tests with enough nodes to make recursive solutions crash with a StackOverflowError or define some rather restrictive constraints for the input, e.g. a maximum of 500 nodes in the passed linked list.
The random tests are now replacing mapped characters correctly.