You are given a string s. You need to reverse the string.
Example 1:
Input:
s = Geeks
Output: skeeG
Example 2:
Input:
s = for
Output: rof
Your Task:
You only need to complete the function reverseWord() that takes s as parameter and returns the reversed string.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1 <= |s| <= 10000

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



def reverseWord(s):

    #your code here

Solutions:
def reverseWord(s):
	return s[::-1]


def reverseWord(s):
	x = ''
	for i in range(len(s) - 1, -1, -1):
		x += s[i]
	return x


def reverseWord(s):
	x = list(s)
	x.reverse()
	return ''.join(x)


def reverseWord(s):
	sh = s[::-1]
	return sh


def reverseWord(s):
	str1 = list(s)
	for i in range(len(s)):
		str1[-(i + 1)] = s[i]
	rev = ''.join(str1)
	return rev


def reverseWord(s):
	s = list(s)
	for i in range(len(s) // 2):
		(s[i], s[len(s) - 1 - i]) = (s[len(s) - 1 - i], s[i])
	return ''.join(s)


def reverseWord(s):
	if len(s) == 1:
		return s[0]
	sol = reverseWord(s[1:]) + s[0]
	return sol


def reverseWord(s):
	rv = ''
	for i in s:
		rv = i + rv
	return rv


def reverseWord(s):
	s1 = ''
	for i in range(0, len(s)):
		s1 = s[i] + s1
	return s1


def reverseWord(s):
	a = ''
	i = len(s) - 1
	while i >= 0:
		a += s[i]
		i -= 1
	return a


def reverseWord(s):
	rev = s[::-1]
	return rev


def reverseWord(s):
	temp = ''
	for i in range(len(s) - 1, -1, -1):
		temp += s[i]
	return temp


def reverseWord(s):
	s1 = s[::-1]
	return s1


def reverseWord(s):
	res = s[::-1]
	return res


def reverseWord(s):
	str = s[::-1]
	return str


def reverseWord(s):
	rev_string = s[::-1]
	return rev_string


def reverseWord(s):
	d = s[::-1]
	return d


def reverseWord(s):
	if len(s) < 2:
		return s[0]
	else:
		return reverseWord(s[1:]) + s[0]


def reverseWord(s):
	reverse_string = s[::-1]
	return reverse_string


def reverseWord(s):
	reverseWord = ''.join(reversed(s))
	return reverseWord


def reverseWord(s):
	st = ''
	for i in range(len(s) - 1, -1, -1):
		st += s[i]
	return st


def reverseWord(s):
	a = s[::-1]
	return a


def reverseWord(s):
	arr = list(s)
	low = 0
	high = len(arr) - 1
	while high > low:
		(arr[low], arr[high]) = (arr[high], arr[low])
		low = low + 1
		high = high - 1
	s = ''
	return s.join(arr)


def reverseWord(s):
	n = len(s)
	r = ''
	for i in range(0, n):
		r = r + s[n - 1 - i]
	return r


def reverseWord(s):
	str = ''
	for i in range(len(s)):
		str = s[i] + str
	return str


def reverseWord(s):
	ans = s[::-1]
	return ans


def reverseWord(s):
	output = ''
	for i in range(len(s) - 1, -1, -1):
		output = output + s[i]
	return output


def reverseWord(s):
	new_s = list(s)
	new_s.reverse()
	str = ''
	for a in new_s:
		str = str + a
	return str


def reverseWord(s):
	t = ''
	for i in range(len(s) - 1, -1, -1):
		t += s[i]
	return t


def reverseWord(s):
	l = s[::-1]
	return l


def reverseWord(s):
	for i in s:
		word = s[::-1]
	return word


def reverseWord(s):
	res = ''
	for i in range(len(s) - 1, -1, -1):
		res += s[i]
	return res


def reverseWord(s):
	return ''.join(list(s)[::-1])


def reverseWord(s):
	x = s[::-1]
	return x


def reverseWord(s):
	v = s[::-1]
	return v
s = 'Greeks'
reverseWord(s)


def reverseWord(A):
	return A[::-1]


def reverseWord(s):
	a = 0
	str1 = ''
	str2 = ''
	for i in range(len(s)):
		if s[i] == ' ':
			break
		else:
			a = a + 1
	for i in range(a):
		str1 = str1 + s[i]
	for i in range(a - 1, -1, -1):
		str2 = str2 + str1[i]
	return str2


def reverseWord(s):
	word = ''
	for i in range(len(s)):
		word += s[-(i + 1)]
	return word


def reverseWord(s):

	def rev(s):
		if len(s) == 1:
			return s[0]
		else:
			return rev(s[1:]) + s[0]
	return rev(s)


def reverseWord(s):
	r = s[::-1]
	return r


def reverseWord(s):

	def reverse(s):
		if len(s) == 1:
			return s[0]
		else:
			return reverse(s[1:]) + s[0]
	return reverse(s)


def reverseWord(s):
	statement = s[::-1]
	return statement


def reverseWord(s):
	rev_s = ''
	for i in range(len(s)):
		rev_s = rev_s + s[len(s) - (i + 1)]
	return rev_s


def reverseWord(s):
	st = s[::-1]
	return st


def reverseWord(s):
	lis = list(s)
	lis1 = lis[::-1]
	ans = ''
	for i in range(len(lis1)):
		ans = ans + str(lis1[i])
	return ans


def reverseWord(s):
	tempS = ''
	for char in s:
		tempS = char + tempS
	return tempS


def reverseWord(s):
	res = ''
	for l in s:
		res = l + res
	return res


def reverseWord(s):
	mystring = ' '
	li = list(s)
	start = 0
	end = len(li) - 1
	while start < end:
		(li[start], li[end]) = (li[end], li[start])
		start += 1
		end -= 1
	mystring = ''.join(li)
	return mystring


def recursiveReverse(s):
	if len(s) == 1:
		return s
	elif len(s) == 2:
		return s[1] + s[0]
	else:
		temp_result = recursiveReverse(s[1:])
		return temp_result + s[0]

def reverseWord(s):
	return recursiveReverse(s)
	return s[::-1]


def reverseWord(s):
	reverseString = ''
	for i in range(len(s)):
		reverseString = s[i] + reverseString
	return reverseString