Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Remove Nodes From Linked List

Medium

Topics
Linked ListStackRecursionMonotonic Stack

Given the head of a linked list, remove every node which has a node with a strictly greater value anywhere to its right. Return the head of the modified list.

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

  • 1 <= number of nodes <= 10^5
  • 1 <= Node.val <= 10^5
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access