Process Singly Linked List Operations
Problem statement
Implement a singly linked list and process two equal-length arrays of operations. For operation type 1, insert values[i] at the front. For type 2, insert it at the back. For type 3, remove the front node when the list is nonempty; its paired value is ignored. Return the list values from front to back after all operations.
Maintain both head and tail pointers so each operation runs in constant time.
Function
processSinglyLinkedListOperations(operationTypes: int[], values: int[]) → int[]Examples
Example 1
operationTypes = [2,2,1,3]values = [4,7,2,0]return = [4,7]Append four and seven, prepend two, then remove the front node.
Example 2
operationTypes = [3,2,3,3]values = [0,8,0,0]return = []Removing from an empty list is a no-op; the later inserted node is removed once.
Constraints
1 <= operationTypes.length == values.length <= 200000operationTypes[i] is 1, 2, or 3values[i] is a signed 32-bit integervalues[i] is ignored when operationTypes[i] is 3