Reverse a linked list - HackerRank - Java

2 days ago
4

Learn how to solve the HackerRank problem whose title is Reverse a linked list, using the Java programming language.

The Data Structures and Algorithms (DSA) lesson uses a recursive approach to solving the question using Java.

Traversing the linked list, you can keep track of current and the previous values.

Then later as you reach the base case, you can return the previous. Then, the recursive calls starting from the end of the list set the current's next to point to the previous one, as it makes it way backward to the beginning of the list.

The time complexity for the solution is O(n) and its space complexity is O(n).

DSA problems are sometimes asked during tech job interviews for positions such as Software Engineer, so you can use the challenge to practice that skill.

Loading comments...