FastPrepImplement Stack Push and Pop Operations
Problems/Implement Stack Push and Pop Operations

Implement Stack Push and Pop Operations

LSEG logoLSEG● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an LSEG onsite interview. The report asks to implement a stack. We chose the interface that runs a batch of push and pop calls, the result of popping an empty stack, and the number limits. Our version is about 75% the same as the reported question.

Implement an initially empty stack that processes the rows of operations in order.

  • [0, value]: push value onto the top of the stack.
  • [1, 0]: pop and return the top value. If the stack is empty, return -1 for that pop.

Return an array containing one result for each pop operation, in operation order. Push operations produce no output. A stack is last in, first out: the most recently pushed value still present must be popped first.

Function

processStack(operations: int[][]) → int[]

Examples

Example 1

operations = [[0,4],[0,7],[1,0],[0,9],[1,0],[1,0]]return = [7,9,4]

The first pop returns 7. After pushing 9, the next two pops return 9 and then 4.

Example 2

operations = [[1,0],[0,-1],[1,0],[1,0]]return = [-1,-1,-1]

The first and last pops are empty. The middle pop returns the actual pushed value -1.

Example 3

operations = []return = []

There are no operations and therefore no pop results.

Constraints

  • 0 <= operations.length <= 100000.
  • Every operation has exactly two integers.
  • Every integer in operations is between -1000000000 and 1000000000, inclusive.
  • Each row is [0, value] for push or [1, 0] for pop.

More LSEG interview questions

  • Recover the Initial Mango PileONSITE INTERVIEW · Seen Jul 2025
  • Retrieve Every Student RecordONSITE INTERVIEW · Seen Sep 2024
  • Count Times Using at Most Two DigitsOA · Seen Jul 2025
  • Maximum Sum of Exactly Three Non-Adjacent ElementsOA · Seen Jul 2025
  • Maximum Word Count in a SentenceOA · Seen Jul 2025
  • Minimum Digit Swaps for the Smallest DifferenceOA · Seen Jul 2025
  • Smallest String After at Most One DeletionOA · Seen Jul 2025
  • Delete One Digit 5 to Maximize the NumberOA · Seen Feb 2025
  • Three-Part Partition with Minimum Largest RangeOA · Seen Feb 2025
  • Transform a String with at Most One OperationOA · Seen Feb 2025

Similar questions at other companies

  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
  • Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Surviving Balls after Directional CollisionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Render a Comment HierarchyAmazon · ONSITE INTERVIEW
  • Asteroid CollisionAdobe · ONSITE INTERVIEWAdobe interview questions
  • Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Asteroid CollisionZscaler · ONSITE INTERVIEWZscaler interview questions
  • Asteroid CollisionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Exclusive Time of FunctionsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions

Interview reports that mention this question

  • LSEG Graduate Technology OA and Interviews: 7 Experiences
All LSEG interview questionsSee LSEG hiring insights
Saved
class Solution {
    public int[] processStack(int[][] operations) {
        // write your code here
    }
}
Checking account…