There's no mutation involved; the first list remains the same. Just populate the other two provided lists from the items of the first list as described. And since this task is specifically to populate these already provided list objects, the kata explicitly does not want you to create and return two new objects.
Isn't mutation an antipattern? Why would we not take a single input and return two new lists?
Updated to include Swift example in description.
It's my first time doing this, so if there is any any thing else missing, please feel free to point it out :)
Missing Swift example in the description.
Updated to Swift 5 + improved the solution size. Please, review and approve :)
Would fail some of the comparisons because the test functions build lists that don't end in an empty node, yet some of the inputs are lists that end in an empty node. Those two are not equivalent so I had to traverse the list and change the empty node to None (Python). Let me know if I just missed something and this isn't an issue.
Let me be more precise,
you implemented the push function which should create a node with .next = null if at the tail but it actually initialises .next = undefined;
Just to let you know.
I did this in C++ just now. To me it looks like the initial solution has been updated to have capital letters for Length and Count.
The example in the description still has lower case functions.
Thanks for the Kata! I knew recursion would help, but I still don't have a strong enough grasp on it to use it confidently. Currently studying the top solutions to see how it's done.
In python, if the user redefines the Node class, the build_one_two_three function does not use the redefined Node. Rather it uses the orignal definition, and therefore causes unexpected behavior with the different types. (E.g. source is of type <class 'setup.Node'> and dest is of type <class 'solution.Node'>). If the user adds or changes methods, they will likely end up with a confusing error for those tests.
This line times out for me: if head is None or head.next is None
Three lists are passed to your function, the source and the other two you have to populate.
I don't understand this Kata for Python 3.6.
So I'm supposed to take a single list and split it into two, right?
So why are there three inputs: source, front, back?
I thought the first thing I'd do is print all three inputs to try and figure this out, or at least just understand what form this list is arriving... but all I get back is a reference to the Node object which I don't feel has been properly explained.
Anyone able to clear up what these instructions want me to do for a Python 3.6 implementation?
Sure, Got it! It was my mistake in interpreting the kata.
The error message is wrong, but the test is correct. build_one_two_three().next.next.next is None, and it has no data attribute.