Skip to content

Practice Remove Nodes From Linked List

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2487
LeetCode Problem

Remove Nodes From Linked List

Problem Statement

You are given the head of a linked list. Remove every node which has a node with a greater value anywhere to the right side of it. Return the head of the modified linked list.

Source: Remove Nodes From Linked List on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
head = [5,2,13,3,8]
Output
[13,8]

# Example 2

Input
head = [1,1,1,1]
Output
[1,1,1,1]

Constraints

The number of the nodes in the given list is in the range [1, 10^5].
1 <= Node.val <= 10^5

Related LeetCode Problems

Practice more problems similar to Remove Nodes From Linked List.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.