Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Yes and no.
So in the end, the actual best practice would be to combine both approaches.
It doesn't recreate the whole list. It recurses through the list until it finds the correct index, then inserts the new Node at that location. If you're referring to
head.next = insert_nth(head.next, index - 1, data)
, that doesn't "recreate" anything, it just sets the new assignment which, in most cases, is the same as the old assignment.If the linked list contains that many elements, then this function will fail. However, lists of that size were not part of this kata. That being said, if I wrote this again, I'd make it tail recursive, and then the list size would not be limited by the stack size.
nice solution (your solution)