This week, we will cover another popular technical interview question from LeetCode’s Top Interview Questions ListReverse Linked List:

Reverse a singly linked list.

Example:

Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL

This article will not give many details about linked lists, but here is a very quick refresher: Linked lists are data structures that represent a series of nodes where each node contains two pieces of information: the value of the node and a pointer/reference to the next node in the list. The beginning of the list is called the head and the node at the end of the list is referred to as the tail, which points to the empty value; null.

Image for post

https://www.geeksforgeeks.org/data-structures/linked-list/

The main benefit of a linked list over an array is an easier insertion or removal of nodes in the list. On the other hand, random access to the data is not allowed because the linked lists do not have indexes, unlike arrays.

#javascript #interview #linked-lists #algorithms #programming

JavaScript: Reverse Linked List
4.05 GEEK