FastPrepDelete a Given Linked-list Node
Problems/Delete a Given Linked-list Node

Delete a Given Linked-list Node

Xilinx logoXilinx● EasyNEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks to remove a linked-list element without traversal. It does not specify how the target is supplied or the tail limitation. This practice gives a non-tail node reference, permits copying the successor value, and returns the modified suffix for the runner. Approximate source match: 75%.

You are given a reference node to a non-tail node in a singly linked list, with no reference to the list head or predecessor. Delete the logical element at that position without traversing the list. Preserve the given node object so aliases to it observe the modified contents. Do not allocate a replacement list.

For this exercise, values may be copied: copy the successor value into the given node and bypass the successor node. Return the same modified node reference so the runner can display the remaining chain. The serialized input and output show only the suffix reachable from this node; any earlier prefix is outside the interface. Node identity beyond retaining this reference is not the deleted logical value.

A tail node cannot be handled under this interface, so a successor is guaranteed. The automated runner compares the returned chain values; alias mutation and no-traversal are explicit implementation requirements.

Function

deleteGivenNode(node: ListNode) → ListNode

Examples

Example 1

node = [4,5,1,9]return = [5,1,9]

Copy the successor value5 into the given node and bypass that successor. The sequence reachable from the same node becomes5,1,9.

Example 2

node = [1,2]return = [2]

The successor is the tail. Copy2 and make the given node the new tail.

Example 3

node = [7,7,8]return = [7,8]

Equal adjacent values do not prevent deletion: one of the two7 occurrences disappears.

Constraints

  • 2 <= reachable node count <= 1000.
  • -1000000 <= node value <= 1000000.
  • The input is a finite acyclic singly linked chain.

More Xilinx problems

  • Count Ones in a 16-bit WordONSITE INTERVIEW · Seen Feb 2019
  • Reservation-station Tag MatchONSITE INTERVIEW · Seen Feb 2019
  • Sort with Two-input ComparatorsONSITE INTERVIEW · Seen Feb 2019
All Xilinx interview questionsSee Xilinx hiring insights
Saved
public ListNode deleteGivenNode(ListNode node) {
    return node;
}
Checking account…