Given a string, say S, print it in reverse manner eliminating the repeated characters and spaces.
Example 1:
Input: S = "GEEKS FOR GEEKS"
Output: "SKEGROF"
Example 2:
Input: S = "I AM AWESOME"
Output: "EMOSWAI"
Your Task:
You don't need to read input or print anything. Your task is to complete the function reverseString() which takes a string S as input parameter and returns a modified string. 
Expected Time Complexity: O(|S|), where |S| denotes length of string.
Expected Auxiliary Space: O(1).

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

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


Solutions:
class Solution:

	def reverseString(self, s):
		result = ''
		s_reverse = s[::-1]
		for char in s_reverse:
			if char == ' ':
				continue
			elif char not in result:
				result += char
		return result


class Solution:

	def reverseString(self, s):
		import collections
		S = ''
		s = s[::-1]
		d = collections.OrderedDict()
		for i in range(len(s)):
			d[s[i]] = i
		for i in d:
			S += i
		S = S.replace(' ', '')
		return S


class Solution:

	def reverseString(self, s):
		str1 = ''
		for i in range(len(s) - 1, -1, -1):
			if s[i] != ' ':
				if s[i] not in str1:
					str1 = str1 + s[i]
		return str1


class Solution:

	def reverseString(self, s):
		b = ''
		a = s[::-1]
		for i in a:
			if i != ' ':
				if i not in b:
					b += i
		return b


class Solution:

	def reverseString(self, s):
		S = ''
		s = s[::-1]
		for i in s:
			if i != ' ':
				if i not in S:
					S += i
		return S


class Solution:

	def reverseString(self, s):
		ans = s[::-1]
		result = ''
		for i in ans:
			if i == ' ':
				continue
			elif i not in result:
				result += i
		return result


class Solution:

	def reverseString(self, s):
		list2 = []
		p = ''
		for i in s[::-1]:
			if i not in p and i.isalpha():
				p += i
		return p


class Solution:

	def reverseString(self, s):
		s = list(s)
		s.reverse()
		z = set()
		a = ''
		for i in range(len(s)):
			if s[i] not in z and s[i] != ' ':
				a = a + s[i]
			z.add(s[i])
		return a


class Solution:

	def reverseString(self, s):
		n = len(s)
		s1 = ''
		dicti = {}
		for i in range(n - 1, -1, -1):
			if s[i] not in dicti and s[i] != ' ':
				s1 += s[i]
				dicti[s[i]] = 1
		return s1


class Solution:

	def reverseString(self, s):
		res = ''
		s = s[::-1]
		for i in s:
			if i == ' ':
				continue
			elif i not in res:
				res += i
		return res


class Solution:

	def reverseString(self, s):
		s = s[::-1]
		a = ''
		for i in range(len(s)):
			if s[i] in a:
				i = i + 1
			elif s[i] == ' ':
				i = i + 1
			else:
				a = a + s[i]
		return a


class Solution:

	def reverseString(self, s):
		s = s.replace(' ', '')
		s = s[::-1]
		a = ''
		for i in s:
			if i in a:
				continue
			a += i
		return a


class Solution:

	def reverseString(self, s):
		freq = {}
		freq[' '] = 1
		ss = ''
		for i in range(len(s) - 1, -1, -1):
			if s[i] not in freq:
				freq[s[i]] = 1
				ss += s[i]
		return ss


class Solution:

	def reverseString(self, s):
		import string
		s = s.replace(' ', '')
		s = s[::-1]
		c = ''
		for i in s:
			if i not in c:
				c = c + i
		return c


class Solution:

	def reverseString(self, s, st=''):
		for i in s[::-1]:
			if i not in st and i != ' ':
				st = st + i
		return st


class Solution:

	def reverseString(self, s):
		s = s.split()
		s = ''.join(s)
		s = list(s)
		s.reverse()
		s = sorted(set(s), key=s.index)
		s = list(s)
		return ''.join(s)


class Solution:

	def reverseString(self, s):
		word = ''
		dict = {}
		for i in range(len(s) - 1, -1, -1):
			if dict.get(s[i]) == None and s[i] != ' ':
				word += s[i]
				dict.update({s[i]: 1})
		return word


class Solution:

	def reverseString(self, s):
		string = ''
		s = s[::-1]
		for index in s:
			if index not in string and ord(index) != 32:
				string += index
		if len(string) == 0:
			return -1
		else:
			return string


class Solution:

	def reverseString(self, s):
		s = s[::-1]
		ans = ''
		for i in s:
			if i not in ans:
				ans += i
		return ans.replace(' ', '')


class Solution:

	def reverseString(self, s):
		str2 = ''
		for i in range(len(s) - 1, -1, -1):
			if s[i] not in str2 and s[i] != ' ':
				str2 += s[i]
		return str2


class Solution:

	def reverseString(self, s):
		rever = s[::-1]
		string = ''
		for i in rever:
			if i not in string:
				string += i
		new = ''
		for i in string:
			if i.isalpha():
				new += i
		return new


class Solution:

	def reverseString(self, s):
		s = s[::-1]
		st = ''
		for i in range(len(s)):
			if s[i] not in st and s[i] != ' ':
				st = st + s[i]
			else:
				continue
		return st


class Solution:

	def reverseString(self, s):
		a = s.split()
		b = ''.join(a)
		new = ''
		for i in b[::-1]:
			if i not in new:
				new += i
		return new


class Solution:

	def reverseString(self, s):
		k = ''
		s = s[::-1]
		for i in s:
			if i == ' ':
				continue
			if i not in k:
				k += i
		return k


class Solution:

	def reverseString(self, s):
		l = list(s)
		str = ''
		for i in range(len(l) - 1, -1, -1):
			if l[i] not in str and l[i] != ' ':
				str = str + l[i]
		return str


class Solution:

	def reverseString(self, s):
		a = s.replace(' ', '')[::-1]
		l = []
		for i in a:
			if i not in l:
				l.append(i)
		return ''.join(l)


from collections import OrderedDict

class Solution:

	def reverseString(self, s):
		ans = ''
		d = OrderedDict()
		for i in s[::-1]:
			if i != ' ':
				d[i] = 1
		for i in d:
			ans += i
		return ans


class Solution:

	def reverseString(self, s):
		s = s[::-1]
		s = s.split(' ')
		s = ''.join(s)
		l = list(s)
		t = []
		for i in l:
			if i not in t:
				t.append(i)
		return ''.join(t)


class Solution:

	def reverseString(self, s):
		w = ''
		l = s.split()
		for i in l[::-1]:
			for j in i[::-1]:
				if j not in w:
					w += j
		return w


class Solution:

	def reverseString(self, s):
		s = s.replace(' ', '')[::-1]
		d = {}
		res = ''
		for i in s:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
				res += i
		return res


class Solution:

	def reverseString(self, s):
		s = s.replace(' ', '')
		s = s[::-1]
		x = ''
		for element in s:
			if element not in x:
				x = x + element
		return x


class Solution:

	def reverseString(self, s):
		l = len(s)
		new_str = ''
		for i in range(l - 1, 0, -1):
			current_str = s[i]
			if current_str != ' ':
				if current_str != s[i - 1] and current_str not in new_str:
					new_str += current_str
		return new_str + s[0] if s[0] not in new_str else new_str


from collections import OrderedDict

class Solution:

	def reverseString(self, s):
		o = OrderedDict()
		for item in s[::-1]:
			o[item] = 1
		if ' ' in o:
			del o[' ']
		return ''.join(o.keys())


class Solution:

	def reverseString(self, s):
		ar = set()
		new = ''
		for i in range(len(s) - 1, -1, -1):
			if s[i] not in ar and s[i] != ' ':
				new += s[i]
				ar = set(new)
		return new


class Solution:

	def reverseString(self, s):
		s1 = s.replace(' ', '')
		s2 = s1[::-1]
		res = ''
		for i in s2:
			if i not in res:
				res += i
		return res


class Solution:

	def reverseString(self, s):
		s = s.replace(' ', '')[::-1]
		res = ''
		for e in s:
			if e not in res:
				res += e
		return res


class Solution:

	def reverseString(self, s):
		s1 = ''
		for i in range(len(s) - 1, -1, -1):
			j = s[i]
			if j not in s1:
				if j != ' ':
					s1 = s1 + j
		return s1


class Solution:

	def reverseString(self, s):
		output = ''
		for item in s[::-1]:
			if item not in output:
				output += item
		return output.replace(' ', '')


class Solution:

	def reverseString(self, s):
		d1 = {}
		str1 = ''
		for i in range(len(s) - 1, -1, -1):
			if s[i] == ' ':
				continue
			if s[i] not in d1:
				d1[s[i]] = 1
				str1 += s[i]
			else:
				d1[s[i]] += 1
		return str1


class Solution:

	def reverseString(self, s):
		res = ''
		for char in s[::-1]:
			if char not in res and (not char.isspace()):
				res += char
		return res


class Solution:

	def reverseString(self, s):
		hmap = {}
		S = ''
		for i in s[::-1]:
			if i in hmap:
				hmap[i] += 1
			else:
				hmap[i] = 1
				S += i
		S = S.replace(' ', '')
		return S


class Solution:

	def reverseString(self, s):
		s1 = s.replace(' ', '')
		s2 = ''
		for i in range(len(s1) - 1, -1, -1):
			if s1[i] not in s2:
				s2 += s1[i]
		return s2


class Solution:

	def reverseString(self, s):
		str = s.replace(' ', '')
		s1 = ''
		s1 += str[::-1]
		s3 = ''
		for i in s1:
			if i not in s3:
				s3 = s3 + i
		return s3


class Solution:

	def reverseString(self, s):
		ans = s[-1]
		for i in range(len(s) - 2, -1, -1):
			if s[i] != ' ' and s[i] not in ans:
				ans += s[i]
		return ans


class Solution:

	def reverseString(self, s):
		r = ''
		for i in range(len(s) - 1, -1, -1):
			if s[i] not in r:
				r += s[i]
		return r.replace(' ', '')


class Solution:

	def reverseString(self, s):
		a = ''
		for x in s[::-1]:
			if x != ' ' and x not in a:
				a += x
		return a