FastPrepDelete a Linked-List Node Given Only Its Pointer
Problems/Delete a Linked-List Node Given Only Its Pointer

Delete a Linked-List Node Given Only Its Pointer

Nutanix logoNutanix● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report published in September 2017 on Nutanix's on-campus interviews for interns lists this among the questions other candidates got in the first interview round. It was not asked to the person who wrote the report. The task is to delete a node from a linked list when you have only a pointer to that node, not the head or any other node.

The report gives no input format, examples or limits. Here the list is singly linked. You get the node with the nodes after it, and you return that same node so the list can be read from it. The node is never the last one. The list from the node has 2 to 1000 nodes. Values are whole numbers from -10^5 to 10^5, and values may repeat. These are choices made for this version.

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

A singly linked list contains a node you must delete, but all you get is node, a reference to that node. You do not get the head of the list or the node before node. Any nodes before node keep pointing to it.

Delete the element held by node: afterwards, reading the list from node onward must give the same values in the same order, with that one element removed. Then return node.

In each test, the input lists the values of node and of the nodes after it, starting with node. The nodes before it are not shown. The judge reads the list starting from the node you return. The judge compares only those values, so it cannot check that you changed the list in place: returning node.next would also pass, but it would not delete anything.

Function

deleteNode(node: ListNode) → ListNode

Examples

Example 1

node = [6,2,9,4]return = [2,9,4]
node
6294
Removed
→
return
294
Moved or new

The input is node, holding 6, followed by nodes holding 2, 9 and 4. Copy 2 from the next node into node, then link node past that next node. Any nodes before node still point to it, and the list from node now reads 2, 9, 4.

Example 2

node = [-3,-3,0]return = [-3,0]
node
-3-30
Removed
→
return
-30
Moved or new

node and the node after it both hold -3. Deleting node removes only one of them, so one -3 is left, followed by 0.

Example 3

node = [10,7]return = [7]
node
107
Removed
→
return
7
Moved or new

node is the second-to-last node. After 7 is copied into it and the last node is skipped, node becomes the last node and holds 7.

Constraints

  • The list that starts at node has between 2 and 1000 nodes, so node is never the last node.
  • Every node value is between -10^5 and 10^5.
  • Values may repeat.

More Nutanix Onsite Interview questions

  • Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
  • Peak Process MemoryONSITE INTERVIEW · Seen Aug 2026
  • Minimum Operations to Transform ArrayONSITE INTERVIEW · Seen Jun 2026
  • Count Connected Components in an Undirected GraphONSITE INTERVIEW · Seen Aug 2025
  • LRU CacheONSITE INTERVIEW · Seen Aug 2025
  • Running Median of a Multilevel Linked List in Level OrderONSITE INTERVIEW · Seen Aug 2025
  • Custom Array IteratorONSITE INTERVIEW · Seen Dec 2024
  • Collapse Runs of Repeated CharactersONSITE INTERVIEW · Seen Nov 2022
  • Anagram Words in a SentenceONSITE INTERVIEW · Seen Apr 2022
  • Sudoku SolverONSITE INTERVIEW · Seen Feb 2022

Similar questions at other companies

  • Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
  • Delete a Doubly Linked List Node at a PositionQualys · ONSITE INTERVIEWQualys interview questions
  • Insert After a Linked-List NodeAMD · ONSITE INTERVIEWAMD interview questions
  • Reverse a Singly Linked ListGoogle · ONSITE INTERVIEWGoogle interview questions
  • Process Singly Linked List OperationsSEDEMAC · ONSITE INTERVIEW
  • Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
  • Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions
  • Reverse a Singly Linked ListGEP · ONSITE INTERVIEW
  • Merge Two Sorted Linked ListsApple · ONSITE INTERVIEWApple interview questions

Interview reports that mention this question

  • Nutanix Intern Debugging Round and Interviews: 25 Experiences

Nutanix interview experiences

  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
All Nutanix interview questionsSee Nutanix 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 deleteNode(ListNode node) {
        // Write your code here.
    }
}
Checking account…