FastPrepReverse a Linked List
Problems/Reverse a Linked List

Reverse a Linked List

Mygate logoMygate● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in Mygate phone screens for a full-time role. The reports name reversing a linked list, without a full interface or limits. We filled those in.

Our version is about 95% the same as the reported questions.

Given the head of a singly linked list, reverse its links and return the new head.

Reuse the existing nodes. Each node must point to the node that preceded it in the original list; the original head becomes the tail and points to null.

The input is acyclic. An empty list remains empty. Lists are displayed as arrays of their node values.

Function

reverseList(head: ListNode) → ListNode

Examples

Example 1

head = [2,5,8]return = [8,5,2]
head
258
→
return
852
Moved or new

The original last node becomes the head. The node order changes from 2 → 5 → 8 to 8 → 5 → 2.

Example 2

head = [4,4,-1]return = [-1,4,4]
head
44-1
→
return
-144
Moved or new

Reversal preserves all three nodes, including both nodes with value 4.

Constraints

  • The list has 0 to 1000 nodes.
  • Each node value is an integer in [-10^6, 10^6].
  • Node values may repeat.
  • The input contains no cycle.

More Mygate Phone Screen questions

  • Employees Earning More Than Their ManagerPHONE SCREEN · Seen Sep 2026
  • Maximum Subarray SumPHONE SCREEN · Seen Sep 2026
  • Users Active in Both January and FebruaryPHONE SCREEN · Seen Sep 2026
  • Elements Occurring More Than n/3 TimesPHONE SCREEN · Seen Jan 2025
  • Frog Jump: Minimum EnergyPHONE SCREEN · Seen Jan 2025
  • Left View of a Binary TreePHONE SCREEN · Seen Jan 2025
  • Two SumPHONE SCREEN · Seen Aug 2024
  • Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Jul 2024
  • Minimum Subarray SumPHONE SCREEN · Seen Sep 2023
  • Remove the Nth Node from the EndPHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Merge Two Sorted ListsLinkedIn · PHONE SCREENLinkedIn interview questions
  • Middle of a Linked ListCisco · PHONE SCREENCisco interview questions
  • Merge Two Sorted ListsIBM · PHONE SCREENIBM interview questions
  • Count Nodes in a ChainApple · PHONE SCREENApple interview questions
  • Detect a Cycle in a Linked ListSalesforce · PHONE SCREENSalesforce interview questions
  • Find the Intersection Node of Two Linked ListsVisa · PHONE SCREENVisa interview questions
  • Linked List Palindrome in Constant SpaceNVIDIA · PHONE SCREENNVIDIA interview questions
  • First Node Two Linked Lists ShareAdobe · PHONE SCREENAdobe interview questions
  • Reverse a Singly Linked ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Merge Two Sorted Linked ListsExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
All Mygate interview questionsSee Mygate 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) {
        // Reverse the links and return the new head.
    }
}
Checking account…