FastPrepReverse a Singly Linked List
Problems/Reverse a Singly Linked List

Reverse a Singly Linked List

GEP logoGEP● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report walks through reversing a singly linked list in place with three pointers. It does not give what the function returns, what happens with empty input, or the limits. This version returns the new head and accepts an empty list. Our version is about 94% the same as the reported question.

You are given the head head of a finite, acyclic singly linked list. Reverse the direction of every next pointer in place and return the new head.

The returned list must contain exactly the original nodes and values in reverse order. Return null when the input list is empty.

Function

reverseList(head: ListNode) → ListNode

Examples

Example 1

head = [1,2,3,4,5]return = [5,4,3,2,1]
head
12345
→
return
54321
Moved or new

Every link is reversed, making 5 the new head and 1 the new tail.

Example 2

head = []return = []
head
empty
return
empty

An empty list remains empty.

Example 3

head = [7]return = [7]
head
7
→
return
7

A one-node list is already reversed.

Constraints

  • 0 <= number of nodes <= 100000.
  • -1000000000 <= node.val <= 1000000000.
  • The input list is finite and acyclic.

More GEP interview questions

  • Deduplicate a Sorted Array In PlacePHONE SCREEN · Seen Sep 2026
  • Find the Missing Number from 1 to nOA · Seen Sep 2026

Similar questions at other companies

  • Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
  • Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
  • Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions
  • Merge Two Sorted Linked ListsApple · ONSITE INTERVIEWApple interview questions
  • Reverse a Singly Linked ListMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Reverse Linked ListThe Walt Disney Company · OA · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Detect a Linked-List CycleGoogle · ONSITE INTERVIEWGoogle interview questions
  • Detect a Cycle in a Linked ListPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
See GEP hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode reverseList(ListNode head) {
        // Write your code here
    }
}
Checking account…