FastPrepImplement a Basic Stack
Problems/Implement a Basic Stack

Implement a Basic Stack

AMD logoAMD● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for a simple stack implementation. This exercise authors a finite operation trace, empty sentinel, bounds and portable interface; approximate source match90%. An exact source date is not available.

Implement the behavior of a last-in-first-out stack for the operation trace. Return one result per operation:0 for push, the removed value for pop, the current value for top, and the number of items for size. Pop/top on an empty stack return-2147483648, which is outside the payload domain. Start with an empty stack.

Function

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

Examples

Example 1

operations = [[0,4],[0,7],[2,0],[1,0],[3,0]]return = [0,0,7,7,1]

After pushing4 then7, top and pop both return7; one item remains.

Example 2

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

The initial pop is empty. Pushing-2 makes it the top.

Constraints

  • 0 <= operations.length <= 500.
  • Every operation has exactly two entries.
  • -1000000 <= operations[i][j] <= 1000000.
  • Every operation is [kind,value], with kind in 0..3. Kind0 adds value; kind1 removes and returns the top item; kind2 returns it without removal; kind3 returns the current size. The second entry is ignored for kinds1..3.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public int[] runStack(int[][] operations) {
    // Write your code here.
}
Checking account…