what is making this loop repeat itself after the first iteration? once we reverse the first list, we need to keep reversing the next set of k nodes with this loop but I’m confused about how it knows to run again instead of going to the next part of the solution?
while (current !== null && i < k) { // reverse 'k' nodes
console.log('run')
next = current.next;
current.next = previous;
previous = current;
current = next;
i += 1;
}
Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Reverse every K-element Sub-list (medium) - Grokking the Coding Interview: Patterns for Coding Questions