Given a string Str which may contains lowercase and uppercase chracters. The task is to remove all duplicate characters from the string and find the resultant string. The order of remaining characters in the output should be same as in the original string.
Example 1:
Input:
Str = geeksforgeeks
Output: geksfor
Explanation: After removing duplicate
characters such as e, k, g, s, we have
string as "geksfor".
Example 2:
Input:
Str = HappyNewYear
Output: HapyNewYr
Explanation: After removing duplicate
characters such as p, e, a, we have
string as "HapyNewYr".
Your Task:
Complete the function removeDuplicates() which takes a string str, as input parameters and returns a string denoting the answer. You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 ≤ N ≤ 10^{5}
String contains uppercase and lowercase english letters.

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3

class Solution:



	

	def removeDuplicates(self,str):

	    # code here

Solutions:
class Solution:

	def removeDuplicates(self, str):
		asci = [0] * 256
		s = ''
		for i in range(len(str)):
			x = ord(str[i])
			asci[x] += 1
		for i in range(len(str)):
			x = ord(str[i])
			if asci[x] > 0:
				s += str[i]
				asci[x] = 0
		return s


class Solution:

	def removeDuplicates(self, str):
		ans = ''
		li = [0] * 256
		for i in str:
			ind = ord(i) - ord('a')
			if li[ind] == 0:
				li[ind] = 1
				ans += i
		return ans


class Solution:

	def removeDuplicates(self, str):
		lst = []
		for i in str:
			if i not in lst:
				lst.append(i)
		return ''.join(lst)


class Solution:

	def removeDuplicates(self, str):
		(m, p) = ({}, '')
		for i in str:
			if i not in m:
				p += i
			m[i] = 1
		return p


class Solution:

	def removeDuplicates(self, str):
		f = ''
		for i in str:
			if i not in f:
				f = f + i
		return f


class Solution:

	def removeDuplicates(self, str):
		str1 = ''
		for i in range(len(str)):
			if str[i] not in str1:
				str1 = str1 + str[i]
		return str1


class Solution:

	def removeDuplicates(self, str):
		from collections import defaultdict
		dic = defaultdict(int)
		ans = ''
		for i in str:
			if dic[i] == 0:
				ans += i
			dic[i] += 1
		return ans


class Solution:

	def removeDuplicates(self, str):
		l = list(str)
		l1 = []
		for i in l:
			if i not in l1:
				l1.append(i)
			else:
				pass
		x = ''.join(l1)
		return x


from collections import OrderedDict

class Solution:

	def removeDuplicates(self, str):
		a = []
		b = ''
		for i in str:
			a.append(i)
		a = list(OrderedDict.fromkeys(a))
		for i in a:
			b += i
		return b


class Solution:

	def removeDuplicates(self, str):
		a = {}
		b = ''
		for i in str:
			if i not in a:
				b += i
			a[i] = 1
		return b


class Solution:

	def removeDuplicates(self, str):
		ms = ''
		d = {}
		for i in str:
			if i not in d:
				ms += i
				d[i] = 1
		return ms


class Solution:

	def removeDuplicates(self, str):
		arr = [char for char in str]
		b = list()
		for i in arr:
			if i not in b:
				b.append(i)
		return ''.join(b)


class Solution:

	def removeDuplicates(self, str):
		p = ''
		for char in str:
			if char not in p:
				p = p + char
		return p


class Solution:

	def removeDuplicates(self, str):
		freq = {}
		s = ''
		for i in range(len(str)):
			if str[i] not in freq:
				s += str[i]
				freq[str[i]] = i
		return s


class Solution:

	def removeDuplicates(self, str):
		l = list(str)
		lst = []
		s = set()
		for i in l:
			if i not in s:
				s.add(i)
				lst.append(i)
		return ''.join(lst)


class Solution:

	def removeDuplicates(self, s: str) -> str:
		seen = set()
		ans = []
		for c in s:
			if c not in seen:
				ans.append(c)
				seen.add(c)
		return ''.join(ans)


class Solution:

	def removeDuplicates(self, str):
		unique = set()
		res = []
		for c in str:
			if c not in unique:
				res.append(c)
				unique.add(c)
		return ''.join(res)


class Solution:

	def removeDuplicates(self, str: str) -> str:
		hash = [0] * 256
		ans = ''
		for c in str:
			if hash[ord(c)] == 0:
				ans += c
				hash[ord(c)] += 1
		return ans


class Solution:

	def removeDuplicates(self, Str):
		unique_chars = set()
		output = ''
		for char in Str:
			if char not in unique_chars:
				unique_chars.add(char)
				output += char
		return output


class Solution:

	def removeDuplicates(self, s):
		for i in range(len(s)):
			s[i].lower()
		d = {}
		for i in s:
			d[i] = 1
		t = ''
		for i in s:
			if d[i] == 1:
				t += i
				d[i] -= 1
		return t


class Solution:

	def removeDuplicates(self, string):
		hash_set = set()
		result = ''
		for char in string:
			if char not in hash_set:
				result += char
				hash_set.add(char)
		return result


class Solution:

	def removeDuplicates(self, str):
		letters = []
		output = ''
		for i in range(len(str)):
			if str[i] in letters:
				continue
			else:
				output += str[i]
				letters.append(str[i])
		return output


class Solution:

	def removeDuplicates(self, s):
		result = ''
		for char in s:
			if char not in result:
				result += char
		return result


class Solution:

	def removeDuplicates(self, str):
		res = ''
		for s in str:
			if s not in res:
				res = res + s
		return res


class Solution:

	def removeDuplicates(self, str):
		seen = set()
		result = ''
		for char in str:
			if char not in seen:
				result += char
				seen.add(char)
		return result


class Solution:

	def removeDuplicates(self, str):
		a = []
		s = ''
		for i in str:
			if i not in a:
				a.append(i)
		for i in a:
			s += i
		return s


class Solution:

	def removeDuplicates(self, str):
		a = list(str)
		l = []
		l.append(a[0])
		for i in range(1, len(a)):
			if a[i] not in l:
				l.append(a[i])
		s = ''.join(l)
		return s


class Solution:

	def removeDuplicates(self, st):
		d = {}
		s = ''
		for i in st:
			if i not in d:
				s += i
				d[i] = 1
		return s


class Solution:

	def removeDuplicates(self, str):
		s = ''
		str = list(str)
		l = []
		for i in str:
			if i in l:
				continue
			else:
				l.append(i)
		for i in l:
			s += i
		return s


class Solution:

	def removeDuplicates(self, str):
		s = ''
		length = len(str)
		for i in range(length):
			c = str[i]
			if c not in s:
				s += c
		return s


class Solution:

	def removeDuplicates(self, str):
		result = []
		sample = ''
		for i in str:
			if i not in result:
				result.append(i)
		for i in result:
			sample += i
		return sample


class Solution:

	def removeDuplicates(self, str):
		hsh = set()
		T = ''
		for ch in str:
			if ch in hsh:
				continue
			else:
				T += ch
				hsh.add(ch)
		return T


class Solution:

	def removeDuplicates(self, str):
		d = {}
		res = ''
		for char in str:
			d[char] = d.get(char, 0) + 1
			if d[char] == 1:
				res += char
		return res


class Solution:

	def removeDuplicates(self, str):
		l = list(str)
		dup = []
		s = ''
		for i in l:
			if i not in dup:
				dup.append(i)
		for j in dup:
			return s.join(dup)


class Solution:

	def removeDuplicates(self, str):
		res = ''
		myDict = {}
		for i in str:
			if i not in myDict:
				res += i
				myDict[i] = 1
		return res


class Solution:

	def removeDuplicates(self, str):
		s = list(str)
		look = {}
		p = ''
		for i in s:
			if i not in look:
				p += i
			look[i] = 1
		return p


class Solution:

	def removeDuplicates(self, str):
		l = []
		for i in str:
			if i not in l:
				l.append(i)
			else:
				continue
		a = ''.join(l)
		return a


class Solution:

	def removeDuplicates(self, str):
		l = []
		for i in str:
			if i in l:
				pass
			else:
				l.append(i)
		joint = ''.join(l)
		return joint


class Solution:

	def removeDuplicates(self, str):
		look_up = {}
		result = ''
		for i in str:
			if i not in look_up.keys():
				result = result + i
				look_up[i] = 1
		return result