You are given a string S, the task is to reverse the string using stack.
 
Example 1:
Input: S="GeeksforGeeks"
Output: skeeGrofskeeG
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function reverse() which takes the string S as an input parameter and returns the reversed string.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1 ≤ length of the string ≤ 100

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Starter code:
def reverse(S):
    
    #Add code here

Solutions:
def reverse(s):
	stack = []
	list1 = []
	for i in range(len(s)):
		stack.append(s[i])
	for i in range(len(stack)):
		list1.append(stack.pop())
	return ''.join(list1)


def reverse(s):
	n = len(s)
	list1 = []
	answer = ''
	for i in s:
		list1.append(i)
	for i in range(len(list1)):
		answer += list1.pop()
	return answer


def reverse(S):
	return S[::-1]


def reverse(S):
	return S[::-1]
	stack = []
	ans = ''
	for val in S:
		stack.append(val)
	while stack:
		ans += stack.pop()
	return ans


def reverse(S):
	stack = []
	result = []
	for alp in S:
		stack.append(alp)
	for _ in range(len(stack)):
		result.append(stack.pop())
	return ''.join(result)


def reverse(s):
	stack = []
	for i in range(len(s) - 1, -1, -1):
		stack.append(s[i])
	return ''.join(stack)


def reverse(s):
	stack = []
	ans = ''
	for i in s:
		stack.append(i)
	for i in range(len(stack)):
		ans += stack.pop()
	return ans


def reverse(s):
	return s[::-1]


def reverse(S):
	stack = []
	n = len(S)
	for i in range(n - 1, -1, -1):
		stack.append(S[i])
	return ''.join(stack)


def reverse(S):
	stack = []
	st = []
	for i in S:
		st.append(i)
	for i in range(len(S)):
		stack.append(st.pop())
	return ''.join(stack)


def reverse(S):
	l = list(S)
	s = ''
	while len(l) > 0:
		s = s + l.pop()
	return s


def reverse(S):
	stack = []
	for char in S:
		stack.append(char)
	reversed_string = ''
	while stack:
		reversed_string += stack.pop()
	return reversed_string


from collections import deque

def reverse(S):
	n = len(S)
	stack = deque()
	for i in S:
		stack.append(i)
	ans = ''
	for i in range(len(stack)):
		ans += stack.pop()
	return ans


def reverse(S):
	ans = ''
	for i in reversed(range(len(S))):
		ans = ans + S[i]
	return ans


def reverse(S):
	n = len(S)
	stack = []
	for i in range(n):
		stack.append(S[i])
	s = ''
	for i in range(n):
		s = s + stack[-1]
		stack.pop()
	return s


def reverse(S):
	stack = []
	stack2 = []
	for i in S:
		stack.append(i)
	for j in range(len(S)):
		stack2.append(stack.pop())
	return ''.join(stack2)


def reverse(S):
	st = []
	for i in S:
		st.append(i)
	s = ''
	while st:
		s += st.pop()
	return s


def reverse(S):
	s1 = []
	s2 = []
	for i in S:
		s1.append(i)
	for i in range(len(s1)):
		s2.append(s1.pop())
	return ''.join(s2)


def reverse(S):
	s = ''
	a = len(S)
	for i in range(len(S)):
		s += S[a - (i + 1)]
	return s


def reverse(S):
	reversedS = ''
	remainingS = len(S)
	while remainingS > 0:
		reversedS += S[remainingS - 1]
		remainingS -= 1
	return reversedS


def reverse(S):
	st = []
	r = ''
	for i in S:
		st.append(i)
	while st:
		r += st.pop()
	return r


def reverse(S):
	stack = []
	newS = ''
	for s in range(len(S)):
		stack.append(S[s])
	while len(stack) > 0:
		newS += stack.pop()
	return newS


def reverse(S):
	st = []
	for i in S:
		st.append(i)
	while len(st):
		print(st.pop(), end='')
	return ''


def reverse(S):
	stack = []
	for i in S:
		stack.append(i)
	s = ''
	for i in range(len(S)):
		x = stack.pop()
		s += x
	return s


def reverse(S):
	stack = []
	for i in S:
		stack.append(i)
	return ''.join(stack[::-1])


def reverse(S):
	stack1 = []
	stack2 = []
	for i in S:
		stack1.append(i)
	for i in range(len(stack1)):
		stack2.append(stack1.pop())
	return ''.join(stack2)


def reverse(S):
	import collections
	ret = ''
	de = collections.deque([*S])
	for i in range(len(de)):
		ret += de.pop()
	return ret


from collections import deque

def reverse(S):
	stack = deque()
	m = len(S)
	i = m - 1
	while i >= 0:
		stack.append(S[i])
		i -= 1
	return ''.join(stack)


def reverse(S):
	stack = []
	astack = []
	for i in S:
		stack.append(i)
	for i in range(len(S)):
		a = stack.pop()
		astack.append(a)
	return ''.join(astack)


def reverse(S):
	ans = ''
	st = []
	for i in S:
		st.append(i)
	while st:
		ans += st.pop()
	return ans


def reverse(s):
	l = []
	for i in s:
		l.append(i)
	t = ''
	while len(l):
		t += l.pop(-1)
	return t


def reverse(S):
	s = []
	for i in range(len(S)):
		s.append(S[i])
	p = ''
	while s:
		a = s.pop()
		p = p + a
	return p


def reverse(S):
	s = []
	a = ''
	for i in S:
		s.append(i)
	while len(s) != 0:
		i = s.pop()
		a = a + i
	return a


def reverse(S):
	output = ''
	length = len(S) - 1
	while length >= 0:
		output = output + S[length]
		length = length - 1
	return output


def reverse(S):
	s = []
	for i in range(len(S) - 1, -1, -1):
		s.append(S[i])
	strr = ''
	for i in range(len(s)):
		strr = strr + s[i]
	return strr


def reverse(S):
	a = []
	str = ''
	for i in S:
		a.append(i)
	b = len(a)
	while b:
		x = a.pop()
		str += x
		b -= 1
	return str


def reverse(S):
	a = []
	u = ''
	for ch in S:
		a.append(ch)
	while len(a) != 0:
		u += a.pop()
	return u


def reverse(S):
	stk = []
	for ch in S:
		stk.append(ch)
	ans = ''
	while stk:
		ans += stk.pop()
	return ans


def reverse(S):
	res = ''
	stack = []
	top = -1
	for i in S:
		stack.append(i)
		top += 1
	while top >= 0:
		x = stack.pop()
		top -= 1
		res += x
	return res


import queue

def reverse(s):
	stack = queue.LifoQueue(len(s))
	for i in s:
		stack.put(i)
	result = ''
	while not stack.empty():
		result += stack.get()
	return result


def reverse(S):
	stack = []
	for i in S:
		stack.append(i)
	S = ''
	while stack:
		S += stack.pop()
	return S


def reverse(S):
	stack = []
	for i in S:
		stack.append(i)
	res = ''
	for i in range(len(stack)):
		res += stack.pop()
	return res


def reverse(S):
	S = list(S)
	S.reverse()
	S = ''.join(S)
	return S


def reverse(S):
	r = []
	s = list(S)
	for i in range(len(s)):
		r.append(s.pop())
	r = ''.join(r)
	return r


from collections import deque

def reverse(S):
	stack = deque()
	a = []
	for i in S:
		stack.append(i)
	while len(stack) > 0:
		a.append(stack.pop())
	return ''.join(a)


def reverse(S):
	arr = []
	S = [x for x in S]
	if not arr:
		while S:
			arr.append(S.pop())
	return ''.join(arr)


def reverse(S):

	class Stack:

		def __init__(self):
			self.items = []

		def isEmpty(self):
			return not self.items

		def push(self, item):
			self.items.append(item)

		def pop(self):
			return self.items.pop()
	stack = Stack()
	rev = ''
	for i in S:
		stack.push(i)
	while stack.isEmpty() == False:
		rev += stack.pop()
	return rev


def reverse(S):
	stack = S[::-1]
	return stack


def reverse(S):
	stack = []
	for r in range(len(S)):
		stack.append(S[r])
	rev = ''
	for x in range(len(stack)):
		rev += stack.pop()
	return rev


import collections

def reverse(S):
	ns = collections.deque(S)
	ns.reverse()
	return ''.join(ns)


def reverse(S):
	l = []
	for i in S:
		l.insert(0, i)
	ans = ''.join(l)
	return ans


def reverse(S):
	res = ''
	for c in range(len(S) - 1, -1, -1):
		res += S[c]
	return res


def reverse(S):
	S = list(S)
	x = []
	for i in range(len(S)):
		x.append(S.pop())
	x = ''.join(x)
	return x


def reverse(S):
	S = ''.join(reversed(S))
	return S


def reverse(S):
	for i in S:
		rev = S[::-1]
	return rev


def reverse(S):
	return str(S)[::-1]


def reverse(S):
	stk = []
	for i in S:
		stk.append(i)
	i = len(S) - 1
	ans = ''
	while i >= 0:
		ans += stk[i]
		i -= 1
	return ans


def reverse(S):
	x = []
	for i in range(len(S) - 1, -1, -1):
		x.append(S[i])
	return ''.join(x)


def reverse(S):
	Stack = []
	for i in S:
		Stack.append(i)
	newstring = ''
	while Stack != []:
		newstring = newstring + Stack.pop()
	return newstring