In this post, we are going to provide a hackerrank solution to Reverse a Linked List.

Linked List: : It is a linear data structure, each node is connected to next node and last node is connected to NULL.

• Each Node is divided into two parts:
• The first part contains the data of the element.
• The second part contains the address of the next node in the list (next).
```SinglyLinkedListNode {
int data;
};
```

## Quick Algorithm to reverse a linked list

1. While(current!=NULL), repeat steps 2, 3 and 4.
2. Save the next node in the “n” pointer.
3. Make the current node point to the previous node.
4. Just update the previous and current node
5. At last, update the head node to the previous node.

## Reverse a Linked List Hackerrank Solution

```SinglyLinkedListNode* reverse(SinglyLinkedListNode*&head) {

while(current!=NULL)
{
//Save the next node
n=current->next;

//Make the current node point to previous node
current->next=prev;

//Just update previous and current node
prev=current;
current=n;

}