A shop has a stack of chocolate boxes each containing a positive number of chocolates. Initially, the stack is empty. During the next N minutes, either of these two things may happen:
- The box of chocolates on top of the stack gets sold
- You receive a box of chocolates from the warehouse and put it on top of the stack.
Determine the number of chocolates in the sold box each time he sells a box.
Notes
- If C[i] = 0, he sells a box. If C[i] > 0, he receives a box containing C[i] chocolates.
- It is confirmed that he gets a buyer only when he has a non-empty stack.
- The capacity of the stack is infinite.
Example 1
Assumptions
Input
- N = 4
- C = [2, 1, 0, 0]
Output: 1 2
Approach
After the first two minutes, the stack is [1, 2].
During the third minute, the box on the top having 1 chocolate is sold.
During the fourth minute, the box on the top having 2 chocolates is sold.
Function description
Complete the function solve() provided in the editor. The function takes the following 2 parameters and returns the solution.
- N: Represents the number of minutes
- C: Represents the description of boxes
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we don’t provide boilerplate code
- The first line contains N denoting the number of minutes.
- The second line contains C denoting the array consisting of the box descriptions.
Output format
Print an array, representing the number of chocolates in the sold box each time you sell a box.
Constraints
Given
Input
- N = 3
- C = [5, 0, 5]
Output: 5
Approach
After the first minute, the stack is [5].
During the second minute, the top of the stack has 5 chocolates.
After the third minute, the stack is [5].
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor