Problem · Design
String Deque with Constant-Time Operations
Learn this problemProblem statement
Implement a deque of strings with a doubly linked list and process operations in order.
push_front valueandpush_back valueinsert a value.pop_frontandpop_backremove and return one end, or returnEMPTY.frontandbackreturn one end without removal, orEMPTY.sizereturns the decimal size.
Return one string for every pop, read, or size command. Every operation must run in O(1) time.
Function
processStringDeque(operations: String[]) → String[]Examples
Example 1
operations = ["push_back a","push_front b","front","back","size","pop_front","pop_back","pop_back"]return = ["b","a","2","b","a","EMPTY"]Values are read and removed from both ends; the final pop sees an empty deque.
Example 2
operations = ["front","push_back x","pop_back","size"]return = ["EMPTY","x","0"]An empty read is reported, then x is inserted and removed.
Constraints
1 <= operations.length <= 200000- Inserted values are nonempty strings without spaces and are never the reserved word
EMPTY. - Every operation uses one of the documented forms.