571. Delete Middle Element of Stack

EasyStackStackRecursion

Given a non-empty stack represented as an array (index 0 is the bottom), delete the middle element (at 0-indexed position n/2, integer division, from the bottom) and return the resulting stack. The input is JSON {stack}.

Input: JSON {stack}.

Output: Array — the stack after removing the middle element.

Examples

Example 1
Input: {"stack":[1,2,3,4,5]}
Output: [1,2,4,5]
Explanation: Remove the element at index 2.
Example 2
Input: {"stack":[10]}
Output: []
Explanation: Removing the only element.
Example 3
Input: {"stack":[1,2,3,4]}
Output: [1,2,4]
Explanation: Remove index 2.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →