Given a stack of integers S, write a program to reverse the stack using recursion.

Problem Note

  • You are not allowed to use loop constructs like while, for..etc, Return S after reversing it using recursion. It is mandatory to reverse S using recursion.

Example 1

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

Example 2

Input: S = [5, 17, 100, 11]
Output: [11, 100, 17, 5]