Given a String. Reverse each word in it where the words are separated by dots.
Example 1:
Input:
S = "i.like.this.program.very.much"
Output: 
i.ekil.siht.margorp.yrev.hcum
Explanation: 
The words are reversed as
follows:"i" -> "i","like"->"ekil",
"this"->"siht","program" -> "margorp",
"very" -> "yrev","much" -> "hcum".
Example 2:
Input: 
S = "pqr.mno"
Output: 
rqp.onm
Explanation: 
The words are reversed as
follows:"pqr" -> "rqp" ,
"mno" -> "onm"
Your Task:
You don't need to read input or print anything. Your task is to complete the functionreverseWords()which takes the string S as input and returns the resultant string by reversing all the words separated by dots.
Expected Time Complexity:O(|S|).
Expected Auxiliary Space:O(|S|).
Constraints:
1<=|S|<=10^{5}

Difficulty: MEDIUM
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(|S|).

Starter code:
#User function Template for python3

class Solution:
    def reverseWords(self, s):
        # code here

Solutions:
class Solution:

	def reverseWords(self, s):
		mm = s.split('.')
		list1 = [i[::-1] for i in mm]
		return '.'.join(list1)


class Solution:

	def reverseWords(self, s):
		st = []
		reverse = ''
		word = ''
		for i in range(len(s)):
			if s[i] != '.':
				word = s[i] + word
			else:
				while len(word) > 0:
					st.append(word[-1])
					word = word[:-1]
				while len(st) > 0:
					reverse = reverse + st.pop()
				reverse += '.'
		while len(word) > 0:
			st.append(word[-1])
			word = word[:-1]
		while st:
			reverse += st.pop()
		return reverse


class Solution:

	def reverseWords(self, s):
		s = s[::-1]
		a = s.split('.')
		a = a[::-1]
		s = '.'.join(a)
		return s


class Solution:

	def reverseWords(self, s):
		words = s.split('.')
		reversed_words = [word[::-1] for word in words]
		return '.'.join(reversed_words)


class Solution:

	def reverseWords(self, s):
		x = s.split('.')
		res = [item[::-1] for item in x]
		return '.'.join(res)


class Solution:

	def reverseWords(self, s):
		l = s.split('.')
		a = []
		for i in l:
			a.append(i[::-1])
		s = '.'.join(a)
		return s


class Solution:

	def reverseWords(self, s):
		i = len(s) - 1
		ans = ''
		while i >= 0:
			st = ''
			while i >= 0 and s[i] != '.':
				st += s[i]
				i -= 1
			if i >= 0:
				ans = '.' + st + ans
			else:
				ans = st + ans
			i -= 1
		return ans


class Solution:

	def reverseWords(self, s):
		a = s.split('.')
		b = [i[::-1] for i in a]
		return '.'.join(b)


class Solution:

	def reverseWords(self, s):
		ans = ''
		stack = []
		for elm in s:
			if elm != '.':
				stack.append(elm)
				continue
			while stack != []:
				ans += stack.pop()
			ans += '.'
		while stack != []:
			ans += stack.pop()
		return ans


class Solution:

	def reverseWords(self, s):
		k = list(s.split('.'))
		for i in range(len(k)):
			k[i] = k[i][::-1]
		a = '.'.join(k)
		return a


class Solution:

	def reverseWords(self, s):
		st = []
		for ele in s:
			st.append(ele)
		l = []
		s = ''
		while len(st) != 0:
			ele = st.pop()
			if ele != '.':
				s += ele
			else:
				l.append(s)
				s = ''
		l.append(s)
		i = 0
		j = len(l) - 1
		while i < j:
			(l[i], l[j]) = (l[j], l[i])
			i += 1
			j -= 1
		ans = '.'.join(l)
		return ans


class Solution:

	def reverseWords(self, s):
		stack = []
		temp = ''
		for i in range(len(s)):
			if s[i] == '.':
				stack.append(temp[::-1] + '.')
				temp = ''
			else:
				temp += s[i]
			if i == len(s) - 1:
				stack.append(temp[::-1])
				return ''.join(stack)


class Solution:

	def reverseWords(self, s):
		lst = s.split('.')
		lst1 = []
		lst2 = []
		for words in lst:
			a = list(words)
			a.reverse()
			lst1.append(a)
		for words in lst1:
			a = ''.join(words)
			lst2.append(a)
		new_s = '.'.join(lst2)
		return new_s


class Solution:

	def reverseWords(self, s):
		stack = []
		temp = ''
		counter = 0
		for i in s:
			counter += 1
			if i == '.':
				stack.append(temp[::-1])
				stack.append('.')
				temp = ''
			else:
				temp += i
			if counter == len(s):
				stack.append(temp[::-1])
				break
		return ''.join(stack)


class Solution:

	def reverseWords(self, s):
		list_a = s.split('.')
		new_arr = ''
		for i in list_a:
			new_arr = new_arr + i[::-1] + '.'
		ans = new_arr[:len(new_arr) - 1]
		return ans


class Solution:

	def reverseWords(self, a):
		b = a.split('.')
		s = ''
		l = []
		for i in b:
			l.append(i[::-1])
		for i in l:
			s += i + '.'
		z = s[:-1]
		return z


class Solution:

	def reverseWords(self, s):
		string = []
		for i in s.split('.'):
			string.append(i[::-1])
		return '.'.join(string)


class Solution:

	def reverseWords(self, s):
		import collections
		ret = ''
		de = collections.deque(s.split('.'))
		top = len(de) - 1
		for x in range(len(de)):
			deWord = collections.deque([*de[x]])
			for i in range(len(deWord)):
				ret += deWord.pop()
			if x != len(de) - 1:
				ret += '.'
		return ret


class Solution:

	def reverseWords(self, s):
		l = list(s.split('.'))
		a = []
		for i in l:
			si = []
			for j in i:
				si.append(j)
			while len(si) > 0:
				a.append(si.pop())
			a.append('.')
		a.pop()
		z = ''.join(a)
		return z


class Solution:

	def reverseWords(self, s):
		l = s.split('.')
		ans = [i[::-1] for i in l]
		return '.'.join(ans)


class Solution:

	def reverseWords(self, s):
		x = s.split('.')
		n = [i[::-1] for i in x]
		return '.'.join(n)


class Solution:

	def reverseWords(self, s):
		list = s.split('.')
		list1 = []
		for i in list:
			i = i[::-1]
			list1.append(i)
		return '.'.join(list1)


class Solution:

	def reverseWords(self, s):
		l = s.split('.')
		l1 = []
		for elem in l:
			l1.append(elem[::-1])
		output = '.'.join(l1)
		return output


class Solution:

	def reverseWords(self, s):
		list1 = []
		for i in s.split('.'):
			list1.append(i)
		res = ''
		for j in range(len(list1) - 1):
			res += list1[j][::-1]
			res += '.'
		res += list1[-1][::-1]
		return res


class Solution:

	def reverseWords(self, s):
		s = s.split('.')
		ls = []
		for i in s:
			x = i[::-1]
			ls.append(x)
		ls = '.'.join(ls)
		return ls


class Solution:

	def reverseWords(self, s):
		li = s.split('.')
		str = ''
		for i in range(0, len(li) - 1):
			str += li[i][::-1] + '.'
		str += li[-1][::-1]
		return str


class Solution:

	def reverseWords(self, s):
		ans = ''
		tmp = ''
		for ch in s:
			if ch != '.':
				tmp = ch + tmp
			else:
				ans += tmp + '.'
				tmp = ''
		ans = ans + tmp
		return ans


class Solution:

	def reverseWords(self, s):
		n = len(s)
		s = s.split('.')
		s1 = ''
		for words in s:
			s1 = s1 + words[::-1] + '.'
		return s1[0:n]


class Solution:

	def reverseWords(self, s):
		stack = []
		reversed_string = ''
		for char in s:
			if char == '.':
				while len(stack) > 0:
					reversed_string += stack.pop()
				reversed_string += '.'
			else:
				stack.append(char)
		while len(stack) > 0:
			reversed_string += stack.pop()
		return reversed_string


class Solution:

	def reverseWords(self, s):
		lst = []
		temp = []
		for i in s:
			if i == '.':
				lst.append(temp)
				temp = []
				continue
			temp.append(i)
		lst.append(temp)
		ans = ''
		for i in lst:
			x = ''
			for j in i:
				x = j + x
			ans += x
			ans += '.'
		return ans[:len(s)]


class Solution:

	def reverseWords(self, s):
		f = s.split('.')
		l = [i[::-1] for i in f]
		k = '.'.join(l)
		return k


class Solution:

	def reverseWords(self, s):
		li = s.split('.')
		for i in range(len(li)):
			li[i] = li[i][::-1]
		st = '.'.join(li)
		return st


class Solution:

	def reverseWords(self, s):
		l = list(s.split('.'))
		k = []
		for i in l:
			k.append(i[::-1])
		return '.'.join(k)


class Solution:

	def reverseWords(self, s):
		st = []
		n = len(s)
		i = 0
		ns = ''
		while i < n:
			while i < n and s[i] != '.':
				st.append(s[i])
				i += 1
			while len(st) > 0:
				ns += st[-1]
				st.pop()
			if i != n:
				ns += '.'
			i += 1
		return ns


class Solution:

	def reverseWords(self, s):
		output = []
		stack = []
		s = s.split('.')
		for word in s:
			u = ''
			a = []
			for ch in word:
				a.append(ch)
			while len(a) != 0:
				u += a.pop()
			output.append(u)
		return '.'.join(output)


class Solution:

	def reverseWords(self, s):
		stack = []
		ans = ''
		for i in s:
			if i != '.':
				stack.append(i)
			else:
				while stack:
					ans += stack.pop()
				ans += '.'
		while stack:
			ans += stack.pop()
		return ans


from collections import deque

class Solution:

	def reverseWords(self, s):
		words = s.split('.')
		reversedSent = []
		for word in words:
			reversedWord = deque(word)
			reversedWord.reverse()
			reversedSent.append(''.join(reversedWord))
		return '.'.join(reversedSent)


from collections import deque

class Solution:

	def reverseWords(self, s):
		words = s.split('.')
		reverse = (word[::-1] for word in words)
		return '.'.join(reverse)


class Solution:

	def reverseWords(self, s):
		words = s.split('.')
		reverse = [word[::-1] for word in words]
		reverse_word = '.'.join(reverse)
		return reverse_word


class Solution:

	def reverseWords(self, s):
		st = ''
		li = s.split('.')
		n = len(li)
		for i in li:
			st += i[::-1]
			n -= 1
			if n != 0:
				st += '.'
		return st


class Solution:

	def reverseWords(self, s):
		stack = []
		prev = -1
		n = len(s)
		i = n - 1
		flag = True
		while i >= 0:
			if s[i] != '.':
				if flag:
					stack.append(s[i])
					flag = False
				else:
					stack[-1] += s[i]
			else:
				stack.append(s[i])
				flag = True
			i -= 1
		stack.reverse()
		n = ''.join((x for x in stack))
		return n


class Solution:

	def reverseWords(self, s):
		stack = s.split('.')
		words = []
		for i in stack:
			words.append(i[::-1])
		return '.'.join(words)


class Solution:

	def reverseWords(self, s):
		l = s.split('.')
		S = ''
		for i in l:
			S = S + i[::-1] + '.'
		return S[:-1]


class Solution:

	def reverseWords(self, s):
		k = s.split('.')
		kp = ''
		for i in k:
			h = ''
			h = h + i
			kp = kp + h[::-1] + '.'
		return kp[:len(kp) - 1]


class Solution:

	def reverseWords(self, s):
		a = s.split('.')
		c = len(a)
		for i in range(c):
			a[i] = a[i][::-1]
		return '.'.join(a)


class Solution:

	def reverseWords(self, s):
		s += '.'
		output = ''
		current = ''
		for i in s:
			if i == '.':
				output += current[::-1] + '.'
				current = ''
			else:
				current += i
		return output[:-1]


class Solution:

	def reverseWords(self, s):
		stack = []
		res = ''
		for i in s:
			if i == '.':
				while len(stack) > 0:
					res += stack.pop()
				res += '.'
			else:
				stack.append(i)
		if len(stack) > 0:
			while len(stack) > 0:
				res += stack.pop()
		return res


class Solution:

	def reverseWords(self, s):
		l = s.split('.')
		for i in range(len(l)):
			w = l[i]
			w = w[::-1]
			l[i] = w
		ns = l[0]
		for i in range(1, len(l)):
			ns = ns + '.' + l[i]
		return ns


class Solution:

	def reverseWords(self, s):
		res = []
		l = s.split('.')
		for word in l:
			res.append(word[::-1])
		return '.'.join(res)


class Solution:

	def reverseWords(self, s):
		x = s.split('.')
		ans = ''
		for i in x:
			y = ''
			for j in i:
				y = j + y
			ans += y + '.'
		ans = ans[:len(ans) - 1]
		return ans


class Solution:

	def reverseWords(self, s):
		S = ''
		strs = ''
		for i in s:
			if i != '.':
				strs += i
			else:
				S += strs[::-1] + '.'
				strs = ''
		S += strs[::-1]
		return S


class Solution:

	def reverseWords(self, s):
		w = s.split('.')
		nw = [i[::-1] for i in w]
		ns = '.'.join(nw)
		return ns


class Solution:

	def reverseWords(self, s):
		words = s.split('.')
		for i in range(0, len(words)):
			words[i] = words[i][::-1]
		return '.'.join(words)


class Solution:

	def reverseWords(self, s):
		l1 = s.split('.')
		ans = ''
		for i in range(len(l1)):
			temp = l1[i]
			ans += temp[::-1]
			if i < len(l1) - 1:
				ans += '.'
		return ans


class Solution:

	def reverseWords(self, s):
		og_array = s.split('.')
		final_string = ''
		str_1 = ''
		word_counter = 0
		for x in og_array:
			dd_array = [*x]
			new_array = []
			q = 1
			while q <= len(dd_array):
				new_array.append(dd_array[len(dd_array) - q])
				q += 1
			string_array = str_1.join(new_array)
			word_counter += 1
			if word_counter != len(og_array):
				final_string += string_array + '.'
			else:
				final_string += string_array
		return final_string


class Solution:

	def reverseWords(self, s):
		z = ''
		k = s.split('.')
		for i in k:
			z = z + i[::-1] + '.'
		n = len(z)
		return z[:n - 1]


class Solution:

	def reverseWords(self, s):
		words = s.split('.')
		return '.'.join((w[::-1] for w in words))


class Solution:

	def reverseWords(self, s):
		k = s.split('.')
		lst = []
		t = 0
		for i in k:
			t = i[::-1]
			lst.append(t)
		q = '.'.join(lst)
		return q


class Solution:

	def reverseWords(self, s):
		x = s.split('.')
		for i in range(len(x)):
			x[i] = x[i][::-1]
		return '.'.join(x)


class Solution:

	def reverseWords(self, s):
		a = list(s.split('.'))
		b = []
		for i in a:
			b.append(i[::-1])
		c = '.'.join(b)
		return c


class Solution:

	def reverseWords(self, s):
		l = []
		S = s.split('.')
		for i in S:
			w = i[::-1]
			l.append(w)
		return '.'.join(l)


class Solution:

	def reverseWords(self, s):
		start_index = 0
		index = 0
		S = list(s)
		while True:
			if start_index + index == len(S) or S[start_index + index] == '.':
				if index > 1:
					for i in range(index // 2):
						tmp = S[start_index + i]
						S[start_index + i] = S[start_index + index - i - 1]
						S[start_index + index - i - 1] = tmp
				if start_index + index == len(S):
					break
				start_index = start_index + index + 1
				index = 0
			else:
				index += 1
		return ''.join(S)