Delete a Linked-List Node Without the Head
Updated
Problem statement
You are given only a node node from a singly linked list. You are not given the list's head. Delete node from the list in place.
The provided node is guaranteed not to be the tail. Copy the successor's value into node, bypass that successor, and return node. The returned list therefore represents the suffix beginning at the original target position after deletion.
Function
deleteNode(node: ListNode) → ListNodeExamples
Example 1
node = [5,1,9]return = [1,9]Removed
Moved or new
The target contains 5. Copy 1 from its successor into the target, then bypass that successor.
Example 2
node = [7,3]return = [3]Removed
Moved or new
The target takes its successor's value 3 and becomes the last node.
Constraints
- The provided
nodeis notnull. - The provided
nodeis not the tail node. - The serialized suffix contains between
2and10^5nodes. - Each node value fits in a 32-bit signed integer.
More Capillary Technologies Onsite Interview questions
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