FastPrepString Deque with Constant-Time Operations
Problems/String Deque with Constant-Time Operations

String Deque with Constant-Time Operations

Goldman Sachs logoGoldman Sachs● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: A Goldman Sachs technical-screen report asks for a string deque implemented with a doubly linked list and constant-time operations. It omits the exact operation set and portable runner; this finite command adapter is an approximately 86% match.

Implement a deque of strings with a doubly linked list and process operations in order.

  • push_front value and push_back value insert a value.
  • pop_front and pop_back remove and return one end, or return EMPTY.
  • front and back return one end without removal, or EMPTY.
  • size returns 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.

More Goldman Sachs problems

  • House Robber IIIPHONE SCREEN · Seen Nov 2026
  • Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public String[] processStringDeque(String[] operations) {
      // write your code here
    }
}
Checking account…