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

Reverse a Singly Linked List

Superhuman logoSuperhuman● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source used the Grammarly label; this item is temporarily grouped under Superhuman and can be reassigned without changing the source record. Only the task name was reported, so the judged conventional contract matches the visible seed at about 85%.

Given the head head of a singly linked list, reverse the direction of every next pointer and return the new head.

The returned list must contain exactly the original nodes and values in reverse order.

Function

reverseList(head: ListNode) → ListNode

Examples

Example 1

head = [1,2,3,4,5]return = [5,4,3,2,1]

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

Example 2

head = [1,2]return = [2,1]

The second node becomes the head and points to the first node.

Example 3

head = [7]return = [7]

A one-node list is already reversed.

Constraints

  • 1 <= number of nodes <= 10^5.
  • -10^9 <= node.val <= 10^9.
  • The input list is finite and contains no cycle.

More Superhuman problems

  • Email Funnel: Opened Within a Day, Replied Within a WeekPHONE SCREEN · Seen Nov 2026
  • Longest Distinct StringOA · Seen Sep 2026
  • Minimum Time on Two ProcessorsOA · Seen Sep 2026
All Superhuman interview questionsSee Superhuman 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…