Implement Stack Push and Pop Operations
Updated
Problem statement
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-1for 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