Delete a Linked-List Node Without the Head
Updated
Problem statement
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) → ListNodeExamples
Example 1
node = [5,1,9]return = [1,9]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]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 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)