Given a string S which consists of alphabets , numbers and special characters. You need to write a program to split the strings in three different strings S1, S2 and S3 such that the string S1 will contain all the alphabets present in S , the string S2 will contain all the numbers present in S and S3 will contain all special characters present in S.  The strings S1, S2 and S3 should have characters in same order as they appear in input.
Example 1:
Input:
S = geeks01for02geeks03!!!
Output:
geeksforgeeks
010203
!!!
Explanation: The output shows S1, S2 and S3. 
Example 2:
Input:
S = **Docoding123456789everyday##
Output:
Docodingeveryday
123456789
**##
Your Task:  
You dont need to read input or print anything. Complete the function splitString() which takes the string S as input parameters and returns a list of strings containing S1, S2 and S3 respectively. If you return an empty string the driver will print -1.
 
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(N)
 
Constraints:
1 ≤ |S| ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:

    def splitString(ob, S): 

        # code here 

       

Solutions:
class Solution:

	def splitString(ob, S):
		S1 = ''
		S2 = ''
		S3 = ''
		for char in S:
			if char.isalpha():
				S1 += char
			elif char.isdigit():
				S2 += char
			else:
				S3 += char
		return (S1, S2, S3)


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		for i in S:
			if i.isalpha():
				s1 += i
			elif i.isdigit():
				s2 += i
			else:
				s3 += i
		return (s1, s2, s3)


class Solution:

	def splitString(ob, S):
		(alph, num, special) = ([], [], [])
		for char in S:
			if char.isalpha():
				alph.append(char)
			elif char.isnumeric():
				num.append(char)
			else:
				special.append(char)
		return (''.join(alph), ''.join(num), ''.join(special))


class Solution:

	def splitString(ob, S):
		res = ['', '', '']
		for ec in S:
			ascii = ord(ec)
			if ascii > 64 and ascii < 91 or (ascii > 96 and ascii < 123):
				res[0] = res[0] + ec
			elif ascii > 47 and ascii < 58:
				res[1] = res[1] + ec
			else:
				res[2] = res[2] + ec
		return res


class Solution:

	def splitString(ob, S):
		S1 = []
		S2 = []
		S3 = []
		for i in S:
			if i.isalpha():
				S1.append(i)
			elif i.isdigit():
				S2.append(i)
			else:
				S3.append(i)
		x = ''.join(S1)
		y = ''.join(S2)
		z = ''.join(S3)
		return [x, y, z]


class Solution:

	def splitString(ob, S):
		S1 = ''
		S2 = ''
		S3 = ''
		for i in S:
			if i.isupper() or i.islower():
				S1 += i
			elif i.isnumeric():
				S2 += i
			else:
				S3 += i
		return [S1, S2, S3]


class Solution:

	def splitString(ob, S):
		a = []
		b = []
		c = []
		for i in S:
			if i.isalpha():
				a.append(i)
			elif i.isdigit():
				b.append(i)
			else:
				c.append(i)
		x = ''.join(a)
		y = ''.join(b)
		z = ''.join(c)
		return [x, y, z]


import re

class Solution:

	def splitString(ob, S):
		(s1, s2, s3) = ('', '', '')
		s1 = ''.join(re.findall('[A-Za-z]+', S))
		s2 = ''.join(re.findall('\\d+', S))
		s3 = ''.join(re.findall('\\W+', S))
		return (s1, s2, s3)


class Solution:

	def splitString(ob, S):
		l = ''
		d = ''
		sp = ''
		for i in S:
			if i.isalpha():
				l += i
			elif i.isdigit():
				d += i
			else:
				sp += i
		return (l, d, sp)


class Solution:

	def splitString(ob, S):
		st = ''
		int = ''
		spe = ''
		for i in S:
			if i.isdigit():
				int += str(i)
			elif i.isalpha():
				st += i
			else:
				spe += i
		return (st, int, spe)


class Solution:

	def splitString(ob, S):
		char = ''
		num = ''
		spc = ''
		for i in S:
			if i.isalpha():
				char += i
			elif i.isdigit():
				num += i
			else:
				spc += i
		return (char, num, spc)


import string

class Solution:

	def splitString(ob, S):
		chars = string.ascii_letters
		nums = string.digits
		specials = string.punctuation
		(s1, s2, s3) = ('', '', '')
		for i in S:
			if i in chars:
				s1 += i
			elif i in nums:
				s2 += i
			else:
				s3 += i
		return (s1, s2, s3)


class Solution:

	def splitString(ob, S):
		s = ['', '', '']
		for i in S:
			if i.isalpha():
				s[0] += i
			elif i.isnumeric():
				s[1] += i
			else:
				s[2] += i
		return s


class Solution:

	def splitString(ob, S):
		S1 = ''
		S2 = ''
		S3 = ''
		a = list(S)
		for i in range(0, len(a)):
			if a[i].isalpha():
				S1 = S1 + ''.join(a[i])
			elif a[i].isnumeric():
				S2 = S2 + ''.join(a[i])
			else:
				S3 = S3 + ''.join(a[i])
		return [S1, S2, S3]


class Solution:

	def splitString(ob, S):
		k = ''
		l = ''
		m = ''
		for i in range(len(S)):
			if 'A' <= S[i] <= 'Z' or 'a' <= S[i] <= 'z':
				k += S[i]
			elif '0' <= S[i] <= '9':
				l += S[i]
			else:
				m += S[i]
		return (k, l, m)


class Solution:

	def splitString(ob, S):
		s1 = []
		s2 = []
		s3 = []
		for i in S:
			if i.islower():
				s1.append(i)
			elif i.isupper():
				s1.append(i)
			elif i.isdigit():
				s2.append(i)
			else:
				s3.append(i)
		return (''.join(s1), ''.join(s2), ''.join(s3))


import string

class Solution:

	def splitString(ob, S):
		alphabet = string.ascii_letters
		number = string.digits
		special = string.punctuation
		(alpha, num, spl) = ('', '', '')
		for a in S:
			if a in alphabet:
				alpha += a
		for n in S:
			if n in number:
				num += n
		for s in S:
			if s in special:
				spl += s
		return (alpha, num, spl)


class Solution:

	def splitString(ob, S):
		(a, d, s) = ('', '', '')
		for i in S:
			if i.isalpha():
				a += i
			elif i.isdigit():
				d += i
			else:
				s += i
		return [a, d, s]


class Solution:

	def splitString(ob, s):
		s1 = ''
		s2 = ''
		s3 = ''
		for i in s:
			if i in 'abcdefghijklmnopqrstuvwxyz' or ord(i) in range(65, 91):
				s1 += i
			elif i in '0123456789':
				s2 += i
			else:
				s3 += i
		l = [s1, s2, s3]
		return l


class Solution:

	def splitString(ob, S):
		c = str(S)
		alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
		digit = '0123456789'
		s1 = ''
		s2 = ''
		s3 = ''
		n = len(S)
		for i in range(n):
			if S[i] in alpha:
				s1 = s1 + S[i]
			elif S[i] in digit:
				s2 += S[i]
			else:
				s3 += S[i]
		return (s1, s2, s3)


class Solution:

	def splitString(ob, S):
		schar = ''
		snumr = ''
		sspec = ''
		for i in S:
			if i.isdigit():
				snumr += i
			elif i.isalpha():
				schar += i
			else:
				sspec += i
		return (schar, snumr, sspec)


class Solution:

	def splitString(ob, S):
		S1 = ''
		S2 = ''
		S3 = ''
		for i in S:
			if i.isnumeric():
				S2 += i
			elif i.isalpha():
				S1 += i
			else:
				S3 += i
		return (S1, S2, S3)


class Solution:

	def splitString(ob, S):
		p = []
		c = []
		e = []
		for i in S:
			if i.isalpha():
				p.append(i)
			elif i.isdigit():
				c.append(i)
			else:
				e.append(i)
		return (''.join(p), ''.join(c), ''.join(e))


class Solution:

	def splitString(ob, S):
		alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		num = '0123456789'
		S1 = ''
		S2 = ''
		S3 = ''
		for i in range(len(S)):
			if S[i] in alpha:
				S1 = S1 + S[i]
			elif S[i] in num:
				S2 = S2 + S[i]
			else:
				S3 = S3 + S[i]
		return (S1, S2, S3)


class Solution:

	def splitString(ob, S):
		s1 = s2 = s3 = ''
		for i in range(len(S)):
			ch = ord(S[i])
			if ch >= 65 and ch <= 90 or (ch >= 97 and ch <= 122):
				s1 += S[i]
			elif S[i].isdigit():
				s2 += S[i]
			else:
				s3 += S[i]
		return [s1, s2, s3]


class Solution:

	def splitString(ob, S):
		strin = list(S)
		s1 = []
		s2 = []
		s3 = []
		for i in range(len(strin)):
			if strin[i].isalpha():
				s1.append(strin[i])
			if strin[i].isdigit():
				s2.append(strin[i])
			if not strin[i].isalnum():
				s3.append(strin[i])
		return (''.join(s1), ''.join(s2), ''.join(s3))


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		l = []
		num = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
		alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
		balpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		for i in S:
			if i in num:
				s2 += i
			elif i in alpha:
				s1 += i
			elif i in balpha:
				s1 += i
			else:
				s3 += i
		l.append(s1)
		l.append(s2)
		l.append(s3)
		return l


class Solution:

	def splitString(ob, S):
		digits_count = ''
		letters_count = ''
		others_count = ''
		for i in S:
			if i.isdigit():
				digits_count += i
			elif i.isalpha():
				letters_count += i
			else:
				others_count += i
		return (letters_count, digits_count, others_count)


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		for char in S:
			if char.isalpha():
				s1 += char
			elif char.isnumeric():
				s2 += char
			else:
				s3 += char
		return [s1, s2, s3]


class Solution:

	def splitString(ob, S):
		s1 = []
		s2 = []
		s3 = []
		for char in S:
			if char.isalpha():
				s1.append(char)
			elif char.isdigit():
				s2.append(char)
			else:
				s3.append(char)
		return (''.join(s1), ''.join(s2), ''.join(s3))


class Solution:

	def splitString(ob, S):
		res = ['' for _ in range(3)]
		for ch in S:
			if ch.isalpha():
				res[0] += ch
			elif ch.isnumeric():
				res[1] += ch
			else:
				res[2] += ch
		return res


class Solution:

	def splitString(ob, S):
		s1 = []
		s2 = []
		s3 = []
		for i in list(S):
			if i.isalpha():
				s1 += i
			elif i.isnumeric():
				s2 += i
			else:
				s3 += i
		return [''.join(s1), ''.join(s2), ''.join(s3)]


class Solution:

	def splitString(ob, S):
		lst = []
		alpha = ''
		numeric = ''
		special1 = ''
		for i in S:
			if ord(i) >= ord('A') and ord(i) <= ord('Z') or (ord(i) >= ord('a') and ord(i) <= ord('z')):
				alpha += i
			elif ord(i) >= ord('0') and ord(i) <= ord('9'):
				numeric += i
			else:
				special1 += i
		lst.append(alpha)
		lst.append(numeric)
		lst.append(special1)
		return lst


class Solution:

	def splitString(ob, S):
		nums = []
		chars = []
		spec = []
		for i in S:
			if i.isdigit() == 1:
				nums.append(i)
			elif i.islower() == 1 or i.isupper() == 1:
				chars.append(i)
			else:
				spec.append(i)
		strchars = ''.join(chars)
		strnums = ''.join(nums)
		strspec = ''.join(spec)
		ans = [0] * 3
		ans[0] = strchars
		ans[1] = strnums
		ans[2] = strspec
		return ans


class Solution:

	def splitString(ob, S):
		a = list(S)
		str = ''
		num = ''
		c = ''
		for i in range(len(a)):
			if a[i].isalpha():
				str += a[i]
			elif a[i].isdigit():
				num += a[i]
			else:
				c += a[i]
		return (str, num, c)


class Solution:

	def splitString(ob, S):
		str = ''
		num = ''
		c = ''
		for i in S:
			if i.isalpha():
				str += i
			elif i.isdigit():
				num += i
			else:
				c += i
		return (str, num, c)


class Solution:

	def splitString(ob, S):
		S1 = ''
		S2 = ''
		S3 = ''
		for i in S:
			if i >= '0' and i <= '9':
				S2 += i
			elif ord(i) >= 65 and ord(i) <= 90:
				S1 += i
			elif ord(i) >= 97 and ord(i) <= 122:
				S1 += i
			else:
				S3 += i
		return [S1, S2, S3]


class Solution:

	def splitString(ob, S):
		str1 = ''
		num = ''
		other = ''
		for i in S:
			if i.isalpha():
				str1 += i
			elif i.isnumeric():
				num += i
			else:
				other += i
		return (str1, num, other)


class Solution:

	def splitString(ob, S):
		ans = []
		S1 = ''
		S2 = ''
		S3 = ''
		alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
		nums = '1234567890'
		for i in S:
			if i in alpha:
				S1 += i
			elif i in nums:
				S2 += i
			else:
				S3 += i
		ans.append(S1)
		ans.append(S2)
		ans.append(S3)
		return ans


class Solution:

	def splitString(ob, s):
		alpha = []
		numeric = []
		special = []
		for i in range(len(s)):
			if s[i].isalpha():
				alpha.append(s[i])
			elif s[i].isalnum():
				numeric.append(s[i])
			else:
				special.append(s[i])
		alpha = ''.join(alpha)
		numeric = ''.join(numeric)
		special = ''.join(special)
		return (alpha, numeric, special)


class Solution:

	def splitString(ob, S):
		(A, B, C) = ([], [], [])
		for i in S:
			if i.isalpha():
				A.append(i)
			elif i.isdigit():
				B.append(i)
			else:
				C.append(i)
		return (''.join(A), ''.join(B), ''.join(C))


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		for i in S:
			if i.isnumeric():
				s2 += i
			elif i.islower() or i.isupper():
				s1 += i
			else:
				s3 += i
		return [s1, s2, s3]


import string

class Solution:

	def splitString(ob, s):
		s1 = ''
		s2 = ''
		s3 = ''
		for i in s:
			if i.isalpha():
				s1 += i
			if i.isdigit():
				s2 += i
			if i in string.punctuation:
				s3 += i
		return (s1, s2, s3)


class Solution:

	def splitString(ob, S):
		res = ''
		res1 = ''
		res2 = ''
		for i in S:
			if i.isalpha():
				res = res + i
			elif i.isdigit():
				res1 = res1 + i
			else:
				res2 = res2 + i
		return (res, res1, res2)


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		for i in range(len(S)):
			if S[i] >= 'A' and S[i] <= 'Z' or (S[i] >= 'a' and S[i] <= 'z'):
				s1 += S[i]
			elif S[i].isdigit():
				s2 += S[i]
			else:
				s3 += S[i]
		return (s1, s2, s3)


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		for i in S:
			if i in 'asdfghjklzxcvbnmqwertyuiopASDFGHJKLZXCVBNMQWERTYUIOP':
				s1 += i
			elif i in '1234567890':
				s2 += i
			else:
				s3 += i
		return (s1, s2, s3)


class Solution:

	def splitString(ob, S):
		ch = ''
		nu = ''
		oth = ''
		for i in S:
			if i.isalpha():
				ch = ch + i
			elif i.isdigit():
				nu = nu + i
			else:
				oth = oth + i
		return (ch, nu, oth)


class Solution:

	def splitString(ob, S):
		list1 = []
		list2 = []
		list3 = []
		for i in S:
			if i.isalpha():
				list1.append(i)
			elif i.isdigit():
				list2.append(i)
			else:
				list3.append(i)
		return [''.join(list1), ''.join(list2), ''.join(list3)]


class Solution:

	def splitString(ob, S):
		l = []
		s1 = ''
		s2 = ''
		s3 = ''
		for i in S:
			if i.isalpha():
				s1 += i
			elif i.isnumeric():
				s2 += i
			else:
				s3 += i
		l.append(s1)
		l.append(s2)
		l.append(s3)
		return l


class Solution:

	def splitString(ob, S):
		result = []
		alpha = ''
		num = ''
		special = ''
		for i in range(len(S)):
			if S[i] >= 'A' and S[i] <= 'Z' or (S[i] >= 'a' and S[i] <= 'z'):
				alpha += S[i]
			elif S[i].isdigit():
				num = num + S[i]
			else:
				special += S[i]
		result.append(alpha)
		result.append(num)
		result.append(special)
		return result


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		for i in range(len(S)):
			temp = ord(S[i])
			if 65 <= temp <= 90 or 97 <= temp <= 122:
				s1 += S[i]
			elif 48 <= temp <= 57:
				s2 += S[i]
			else:
				s3 += S[i]
		return [s1, s2, s3]


class Solution:

	def splitString(ob, S):
		a = 'abcdefghijklmnopqrstuvwxyz'
		n = '0123456789'
		a1 = ''
		n1 = ''
		s1 = ''
		for elem in S:
			if elem.lower() in a:
				a1 += elem
			elif elem in n:
				n1 += elem
			else:
				s1 += elem
		return (a1, n1, s1)


class Solution:

	def splitString(ob, S):
		s1 = ''
		s2 = ''
		s3 = ''
		ans = [0] * 3
		n = len(S)
		for i in range(n):
			if S[i].isdigit():
				s2 += S[i]
			elif S[i].isalpha():
				s1 += S[i]
			else:
				s3 += S[i]
		ans[0] = s1
		ans[1] = s2
		ans[2] = s3
		return ans


class Solution:

	def splitString(ob, S, al='', num='', sp=''):
		for i in S:
			if 'a' <= i <= 'z' or 'A' <= i <= 'Z':
				al += i
			elif '0' <= i <= '9':
				num += i
			else:
				sp += i
		return (al, num, sp)


class Solution:

	def splitString(ob, S):
		S1 = ''
		S2 = ''
		S3 = ''
		lst = []
		lst.append(S1)
		lst.append(S2)
		lst.append(S3)
		for i in range(len(S)):
			if S[i].isalpha():
				S1 += S[i]
			elif S[i].isnumeric():
				S2 += S[i]
			else:
				S3 += S[i]
		if len(S1) >= 1:
			lst[0] = S1
		if len(S2) >= 1:
			lst[1] = S2
		if len(S3) >= 1:
			lst[2] = S3
		return lst


class Solution:

	def splitString(ob, S):
		strg = ''
		num = ''
		sp = ''
		for i in S:
			if i.islower() or i.isupper():
				strg += i
			elif i.isnumeric():
				num += i
			else:
				sp += i
		return (strg, num, sp)


class Solution:

	def splitString(ob, S):
		alpha = ''
		numeric = ''
		special = ''
		for i in S:
			if i.isalpha():
				alpha += i
			elif i.isnumeric():
				numeric += i
			else:
				special += i
		return [alpha, numeric, special]


class Solution:

	def splitString(ob, S):
		letters = 'abcdefghijklmnopqrstuvwxyz'
		numbers = '0123456789'
		sc = '!@#$%^&*_-+,./?><`~'
		sl = ''
		sn = ''
		ssc = ''
		for i in S:
			if i.lower() in letters:
				sl += i
			elif i in numbers:
				sn += i
			else:
				ssc += i
		return [sl, sn, ssc]