FastPrepDelete a Linked-List Node Without the Head
Problems/Delete a Linked-List Node Without the Head

Delete a Linked-List Node Without the Head

Morgan Stanley logoMorgan Stanley● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Morgan Stanley onsite interview for interns. The author asks to delete a linked-list node without the head pointer. Here you are given a node that is not the tail, in a singly linked list with no cycle. Deleting means changing values, not unlinking. You return that same node so the changed rest of the list can be seen. We chose the limits and the rules about shared references.

Our version is about 90% the same as the reported question.

You are given only a reference node to a non-tail node of a singly linked list. You do not receive the head pointer or a predecessor. Delete the logical element originally stored at this node while preserving the order of all later elements. Modify the existing nodes; do not allocate a replacement list.

For this exercise, deletion means the list’s value sequence loses that one occurrence. The supplied node object remains available: values may be copied and a later node bypassed. There are no other external references whose node identities must be preserved.

The input representation lists only the values reachable from node, starting at the supplied node; an earlier prefix is not provided. Return that same reference after mutation so the judge can observe the resulting suffix. Its values must equal the original suffix with its first occurrence removed. The node always has a successor; tail deletion is outside this exercise.

Function

deleteGivenNode(node: ListNode) → ListNode

Examples

Example 1

node = [5,1,9]return = [1,9]
node
519
Removed
→
return
19
Moved or new

The supplied suffix is 5→1→9. Copy the successor’s 1 into the supplied node and bypass that successor. Returning the supplied node now exposes 1→9, deleting the original 5 occurrence without a head pointer.

Example 2

node = [8,8]return = [8]
node
88
Removed
→
return
8

Both nodes store 8, but they are separate occurrences. After deletion, the suffix contains exactly one 8 node, not two.

Constraints

  • For this exercise, assume 2 <= suffix length <= 500.
  • For this exercise, assume -1000000 <= node values <= 1000000.
  • The supplied suffix is a valid finite acyclic singly linked list with no external node-identity aliases.

More Morgan Stanley Onsite Interview questions

  • Generate Strings of Length at Least ThreeONSITE INTERVIEW · Seen Sep 2026
  • Maximum Concurrent ProcessesOA · ONSITE INTERVIEW · Seen Sep 2026
  • Kth Largest Array ElementONSITE INTERVIEW · Seen Jul 2026
  • Run-Length Encode Consecutive Letter RunsONSITE INTERVIEW · Seen Jul 2026
  • Maximum Edge Removals for Two TravelersONSITE INTERVIEW · Seen Oct 2025
  • Remove K DigitsONSITE INTERVIEW · Seen Oct 2025
  • Count Ideal ArraysONSITE INTERVIEW · Seen Aug 2023
  • Distinct Palindrome PartitionsONSITE INTERVIEW · Seen Aug 2023
  • LFU Cache OperationsONSITE INTERVIEW · Seen Aug 2023
  • All-Pairs Shortest PathsOA · ONSITE INTERVIEW · Seen Feb 2022

Similar questions at other companies

  • Reverse a Sublist of a Linked ListSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • LRU CacheLotusFlare · ONSITE INTERVIEW
  • LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Remove Nth Node From End of ListDruva · ONSITE INTERVIEW
  • Merge a List In Between Two PositionsWalmart · ONSITE INTERVIEWWalmart interview questions
  • LRU CacheJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • LRU Cache OperationsHevo Data · ONSITE INTERVIEW
  • LRU Cache OperationsLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • First-Fit Memory AllocatorGoogle · ONSITE INTERVIEWGoogle interview questions
  • Find the Entry of a Linked List CycleQualys · ONSITE INTERVIEWQualys interview questions

Interview reports that mention this question

  • Morgan Stanley Intern Oldest Loops: 5 Experiences (Part 5 of 5)

Morgan Stanley interview experiences

  • Morgan Stanley Apprenticeship and Tech Interviews: 6 Experiences
  • Morgan Stanley New Grad Technology Analyst: 2 Experiences
  • Morgan Stanley Intern OOP Loops: 5 Experiences (Part 4 of 5)
  • Morgan Stanley Intern Earlier Loops: 5 Experiences (Part 3 of 5)
  • Morgan Stanley Intern Tech Rounds: 5 Experiences (Part 2 of 5)
All Morgan Stanley interview questionsSee Morgan Stanley 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 deleteGivenNode(ListNode node) {
        // Modify the given node and return that same reference.
    }

}
Checking account…