Reverse a linked list
mediumSaving `next` before overwriting `curr.next` is not defensive coding - it is mandatory. Swap those two lines and the rest of the list becomes unreachable.
Worst
O(n)Space O(1)Loading the reverse a linked list engine…