Given two strings s1 and s2. Modify both the strings such that all the common characters of s1 and s2 are to be removed and the uncommon characters of s1 and s2 are to be concatenated.
Note: If all characters are removed print -1.
Example 1:
Input:
s1 = aacdb
s2 = gafd
Output: cbgf
Explanation: The common characters of s1
and s2 are: a, d. The uncommon characters
of s1 and s2 are c, b, g and f. Thus the
modified string with uncommon characters
concatenated is cbgf.
Example 2:
Input:
s1 = abcs
s2 = cxzca
Output: bsxz
Explanation: The common characters of s1
and s2 are: a,c. The uncommon characters
of s1 and s2 are b,s,x and z. Thus the
modified string with uncommon characters
concatenated is bsxz.
Your Task:
The task is to complete the function concatenatedString() which removes the common characters, concatenates, and returns the string. If all characters are removed then return -1.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Number of distinct characters).
Note: N = |Length of Strings|
Constraints: 
1 <= |Length of Strings| <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: 
#User function Template for python3

class Solution:
    
    #Function to remove common characters and concatenate two strings.
    def concatenatedString(self,s1,s2):
        #code here
        

Solutions:
class Solution:

	def concatenatedString(self, s1, s2):
		s1_set = set(s1)
		s2_set = set(s2)
		temp = ''
		for v in s1:
			if v not in s2_set:
				temp += v
		for v in s2:
			if v not in s1_set:
				temp += v
		return temp if len(temp) > 0 else -1


class Solution:

	def concatenatedString(self, s1, s2):
		k = ''
		for i in s1:
			if i not in s2:
				k = k + i
		for i in s2:
			if i not in s1:
				k = k + i
		if k == '':
			return -1
		return k


class Solution:

	def concatenatedString(self, s1, s2):
		s = ''
		a = set()
		b = set()
		for i in range(len(s1)):
			a.add(s1[i])
		for j in range(len(s2)):
			b.add(s2[j])
		for k in range(len(s1)):
			if s1[k] not in b:
				s += str(s1[k])
				continue
		for l in range(len(s2)):
			if s2[l] not in a:
				s += str(s2[l])
				continue
		if s == '':
			return -1
		else:
			return s


class Solution:

	def concatenatedString(self, s1, s2):
		result = ''
		s3 = s1 + s2
		for i in s3:
			if i not in s1 or i not in s2:
				result += i
		if result == '':
			return -1
		return result


class Solution:

	def concatenatedString(self, s1, s2):
		str1 = ''
		for i in range(len(s1)):
			if s1[i] not in s2:
				str1 = str1 + s1[i]
		for j in range(len(s2)):
			if s2[j] not in s1:
				str1 = str1 + s2[j]
		if len(str1) > 0:
			return str1
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		S1 = [x for x in s1 if x not in s2]
		S2 = [x for x in s2 if x not in s1]
		s = S1 + S2
		if len(s) < 1:
			return -1
		else:
			j = ''
			p = j.join(s)
			return p


class Solution:

	def concatenatedString(self, s1, s2):
		s = ''
		cnt1 = 0
		cnt2 = 0
		for i in s1:
			if i not in s2:
				s = s + i
		for i in s2:
			if i not in s1:
				s = s + i
		if len(s) == 0:
			return -1
		else:
			return s


class Solution:

	def concatenatedString(self, s1, s2):
		c = ''
		for i in range(len(s1)):
			if s1[i] not in s2:
				c += s1[i]
		for i in range(len(s2)):
			if s2[i] not in s1:
				c += s2[i]
		if len(c) == 0:
			return -1
		return c


class Solution:

	def concatenatedString(self, s1, s2):
		rs = []
		a = list(s1)
		b = list(s2)
		for i in a:
			if i not in b:
				rs.append(i)
		for j in b:
			if j not in a:
				rs.append(j)
		if rs == []:
			return -1
		return ''.join(rs)


class Solution:

	def concatenatedString(self, s1, s2):
		s3 = s1 + s2
		ans = ''
		for i in s3:
			if i not in s1 or i not in s2:
				ans += i
		if len(ans) == 0:
			return '-1'
		else:
			return ans


class Solution:

	def concatenatedString(self, s1, s2):
		s = set(s1)
		s_ = set(s2)
		t = s1 + s2
		temp = ''
		for i in t:
			if i in s and i in s_:
				continue
			else:
				temp += i
		if len(temp) == 0:
			return -1
		return temp


class Solution:

	def concatenatedString(self, s1, s2):
		s = ''
		for i in s1:
			if i not in s2:
				s += i
		for i in s2:
			if i not in s1:
				s += i
		if s != '':
			return s
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		intersect_l = set(s1).intersection(set(s2))
		s1 = list(s1)
		s2 = list(s2)
		l = []
		for i in range(len(s1)):
			if s1[i] not in intersect_l:
				l.append(s1[i])
		for i in range(len(s2)):
			if s2[i] not in intersect_l:
				l.append(s2[i])
		if len(l) > 0:
			return ''.join(l)
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		st = ''
		for i in s1:
			if i not in s2:
				st += i
		for j in s2:
			if j not in s1:
				st += j
		if st:
			return st
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		s3 = ''
		s4 = ''
		for i in s1:
			if i not in s2:
				s3 += i
		for i in s2:
			if i not in s1:
				s4 += i
		s5 = s3 + s4
		if len(s5) == 0:
			return -1
		else:
			return s5


class Solution:

	def concatenatedString(self, s1, s2):
		con = ''
		for i in s1:
			if i not in s2:
				con += i
		for i in s2:
			if i not in s1:
				con += i
		if len(con) != 0:
			return con
		return -1


class Solution:

	def concatenatedString(self, s1, s2):
		l1 = []
		for i in s1:
			if i not in s2:
				l1.append(i)
		for i in s2:
			if i not in s1:
				l1.append(i)
		if l1 == []:
			return -1
		else:
			return ''.join(l1)


class Solution:

	def concatenatedString(self, s1, s2):
		ans = ''
		ad = s1 + s2
		for i in ad:
			if i not in s1 or i not in s2:
				ans += i
		if ans == '':
			return -1
		return ans


class Solution:

	def concatenatedString(self, s1, s2):
		set1 = set(s1)
		set2 = set(s2)
		uncommon1 = ''
		uncommon2 = ''
		for i in s1:
			if i not in s2:
				uncommon1 += i
		for i in s2:
			if i not in s1:
				uncommon2 += i
		result = uncommon1 + uncommon2
		if len(result) == 0:
			return '-1'
		else:
			return result


class Solution:

	def concatenatedString(self, s1, s2):
		a = list(set(s1).intersection(set(s2)))
		(f, l) = ('', '')
		for i in s1:
			if i not in a:
				f += i
		for i in s2:
			if i not in a:
				l += i
		if f + l == '':
			return -1
		return f + l


class Solution:

	def concatenatedString(self, s1, s2):
		res = ''
		for ch in s1:
			if ch in s2:
				s1 = s1.replace(ch, '')
				s2 = s2.replace(ch, '')
		if len(s1) + len(s2) == 0:
			return -1
		return s1 + s2


class Solution:

	def concatenatedString(self, s1, s2):
		s = ''
		for i in s1:
			if i not in s2:
				s += i
		for j in s2:
			if j not in s1:
				s += j
		if len(s) == 0:
			return -1
		return s


class Solution:

	def concatenatedString(self, s1, s2):
		k = ''
		for i in s1:
			if i not in s2:
				k += i
		for i in s2:
			if i not in s1:
				k += i
		if len(k) > 0:
			return k
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		res = ''
		for i in range(len(s1)):
			if s1[i] not in s2:
				res += s1[i]
		for i in range(len(s2)):
			if s2[i] not in s1:
				res += s2[i]
		if res == '':
			return -1
		else:
			return res


class Solution:

	def concatenatedString(self, s1, s2):
		str1 = ''
		str2 = ''
		for i in s1:
			if i not in s2:
				str1 += i
		for i in s2:
			if i not in s1:
				str2 += i
		s = str1 + str2
		if len(s) == 0:
			return -1
		return ''.join(s)


class Solution:

	def concatenatedString(self, s1, s2):
		se1 = set(list(s1))
		se2 = set(list(s2))
		s = ''
		for i in s1:
			if i not in se2:
				s += i
		for i in s2:
			if i not in se1:
				s += i
		return s if s != '' else '-1'


class Solution:

	def concatenatedString(self, s1, s2):
		set1 = set(s1)
		set2 = set(s2)
		s1_new = ''
		s2_new = ''
		for c in s1:
			if c not in set2:
				s1_new += c
		for c in s2:
			if c not in set1:
				s2_new += c
		result = s1_new + s2_new
		if result:
			return result
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		l1 = [i for i in s1 if i not in s2]
		l2 = [i for i in s2 if i not in s1]
		if len(l1 + l2) != 0:
			return ''.join(l1 + l2)
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		a = ''
		b = ''
		for i in s1:
			if i not in s2:
				a += i
		for j in s2:
			if j not in s1:
				b += j
		if len(a + b) > 0:
			return a + b
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		l = []
		for i in s1:
			if i not in s2:
				l.append(i)
		for i in s2:
			if i not in s1:
				l.append(i)
		if len(l) != 0:
			ansi = ''.join(l)
			return ansi
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		s = ''
		t = ''
		for i in s1:
			if i not in s2:
				s += i
		for i in s2:
			if i not in s1:
				t += i
		if len(s) >= 1 or len(t) >= 1:
			return s + t
		return -1


class Solution:

	def concatenatedString(self, s1, s2):
		res_s1 = ''
		res_s2 = ''
		for i in s1:
			if i not in s2:
				res_s1 += i
		for i in s2:
			if i not in s1:
				res_s2 += i
		if len(res_s1) >= 1 or len(res_s2) >= 1:
			return res_s1 + res_s2
		return -1


class Solution:

	def concatenatedString(self, s1, s2):
		for i in s1:
			if i in s2:
				s1 = s1.replace(i, '')
				s2 = s2.replace(i, '')
		if len(s1 + s2) == 0:
			return -1
		return s1 + s2


class Solution:

	def concatenatedString(self, s1, s2):
		d1 = {}
		d2 = {}
		for i in s1:
			if i in d1:
				d1[i] += 1
			else:
				d1[i] = 1
		for i in s2:
			if i in d2:
				d2[i] += 1
			else:
				d2[i] = 1
		for i in d1:
			if i in d2:
				d1[i] = 0
				d2[i] = 0
		ans = ''
		for i in s1:
			if d1[i] != 0:
				ans = ans + i
		for i in s2:
			if d2[i] != 0:
				ans = ans + i
		if len(ans) != 0:
			return ans
		return -1


class Solution:

	def concatenatedString(self, s1, s2):
		for each in set(s1) & set(s2):
			s1 = s1.replace(each, '')
			s2 = s2.replace(each, '')
		if s1 == '' and s2 == '':
			return -1
		return s1 + s2


class Solution:

	def concatenatedString(self, s1, s2):
		result = ''
		for c in s1:
			if c not in s2:
				result += c
		for c in s2:
			if c not in s1:
				result += c
		if result != '':
			return result
		return -1


class Solution:

	def concatenatedString(self, s1, s2):
		k = ''
		s2 = list(s2)
		s1 = list(s1)
		i = 0
		while i < len(s1):
			if s1[i] in s2:
				i += 1
			else:
				k += s1[i]
				i += 1
		i = 0
		while i < len(s2):
			if s2[i] in s1:
				i += 1
			else:
				k += s2[i]
				i += 1
		if len(k) > 0:
			return k
		return -1


class Solution:

	def concatenatedString(self, s1, s2):
		set1 = set(s1)
		set2 = set(s2)
		string = ''
		for char in s1:
			if char not in set2:
				string += char
		for char in s2:
			if char not in set1:
				string += char
		if string == '':
			return -1
		return string


class Solution:

	def concatenatedString(self, s1, s2):
		lis = []
		for i in s1:
			if i not in s2:
				lis.append(i)
		for j in s2:
			if j not in s1:
				lis.append(j)
		b = ''.join(lis)
		if len(b) > 0:
			return b
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		concat = ''
		for x in s1:
			if x not in s2:
				concat += x
		for x in s2:
			if x not in s1:
				concat += x
		if len(concat) > 0:
			return concat
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		s1_set = set(s1)
		s2_set = set(s2)
		string = ''
		for i in s1:
			if i not in s2_set:
				string += i
		for i in s2:
			if i not in s1_set:
				string += i
		if string == '':
			return -1
		return string


class Solution:

	def concatenatedString(self, s1, s2):
		result = [char for char in s1 + s2 if char in s1 and (not char in s2) or (char in s2 and char not in s1)]
		if len(result) != 0:
			return ''.join(result)
		else:
			return -1


class Solution:

	def concatenatedString(self, s1, s2):
		cms = set(s) & set(p)
		rst = []
		for i in s:
			if i not in cms:
				rst.append(i)
		for i in p:
			if i not in cms:
				rst.append(i)
		if len(rst) == 0:
			return -1
		else:
			return ''.join(rst)


class Solution:

	def concatenatedString(self, s1, s2):
		lst = []
		for i in s1:
			if i not in s2:
				lst.append(i)
		for i in s2:
			if i not in s1:
				lst.append(i)
		if len(lst) == 0:
			return -1
		else:
			str = ''
			for i in lst:
				str += i
			return str


class Solution:

	def concatenatedString(self, s1, s2):
		str1 = ''
		str2 = ''
		for i in s1:
			if i not in s2:
				str1 += i
		for j in s2:
			if j not in s1:
				str2 += j
		str = str1 + str2
		if str == '':
			return -1
		else:
			return str


class Solution:

	def concatenatedString(self, s1, s2):
		s = ''
		st = ''
		for i in s1:
			if i not in s2:
				s += i
		for i in s2:
			if i not in s1:
				st += i
		s3 = s + st
		if len(s3) == 0:
			return -1
		else:
			return s3