Tap here to switch tabs
Problem
Submissions

Problem: Build an Array With Stack Operations

med
30 min
Try to solve the Build an Array With Stack Operations problem.

Statement

You are given an integer array target and an integer n.

You have an empty stack and a stream of integers from 11 to n in strictly increasing order. In each step, you process the next integer from the stream using the following operations:

  • "Push": Pushes the current integer from the stream onto the stack.

  • "Pop": Removes the integer at the top of the stack.

You must build the target array using the stack such that the elements in the stack from bottom to top form target. You must stop performing operations immediately once the stack matches target.

Return the list of operations performed to build target.

Constraints:

  • 1≤1 \leq target.length ≤100\leq 100

  • 1≤1 \leq n ≤100\leq 100

  • 1≤1 \leq target[i] ≤\leq n

  • target is strictly increasing.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Build an Array With Stack Operations

med
30 min
Try to solve the Build an Array With Stack Operations problem.

Statement

You are given an integer array target and an integer n.

You have an empty stack and a stream of integers from 11 to n in strictly increasing order. In each step, you process the next integer from the stream using the following operations:

  • "Push": Pushes the current integer from the stream onto the stack.

  • "Pop": Removes the integer at the top of the stack.

You must build the target array using the stack such that the elements in the stack from bottom to top form target. You must stop performing operations immediately once the stack matches target.

Return the list of operations performed to build target.

Constraints:

  • 1≤1 \leq target.length ≤100\leq 100

  • 1≤1 \leq n ≤100\leq 100

  • 1≤1 \leq target[i] ≤\leq n

  • target is strictly increasing.