Delete Middle Element from Stack

You are provided with a stack ARR of size 'N+1'. Your task is to delete the middlemost element so that the size of the resulting stack becomes 'N'.

Recall that a stack is a linear data structure where both insertion and deletion of elements occur at the top, following the LIFO (Last In First Out) or FILO (First In Last Out) principles.

Input:

The first line of input consists of an integer 'T', the number of test cases.
Each test case begins with an integer 'N', indicating that the stack initially contains 'N+1' elements.
The following line in each test case includes 'N+1' space-separated integers representing stack elements.

Output:

For each test case, output 'N' space-separated integers showing the stack after the middle element is removed.
Each test case's result should be printed on a new line.

Example:

Input: ARR = [1, 2, 3, 4, 5], N = 4
Output: ARR = [1, 2, 4, 5]

Input: ARR = [5, 6, 7, 8], N = 3
Output: ARR = [5, 7, 8]

Constraints:

  • 1 <= T <= 100
  • 1 <= N+1 <= 3000
  • 0 <= data <= 10^9
Note:
No need to print anything; focus on implementing the function correctly.
AnswerBot
4mo

Implement a function to delete the middle element from a stack, reducing its size by 1.

  • Iterate through the stack to find the middle element based on the stack size.

  • Remove the middle element and shift ...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at MedTourEasy

Q. What is the need for virtual memory?
Q. Anagram Pairs Verification Problem Your task is to determine if two given string...read more
Q. Decimal to Octal Conversion Problem Statement Convert a given decimal number int...read more
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits