Given a string which is basically a sentence without spaces between words. However the first letter of every word is in uppercase. You need to print this sentence after following amendments:
(i) Put a single space between these words
(ii) Convert the uppercase letters to lowercase.
Note: The first character of the string can be both uppercase/lowercase.
Example 1:
Input:
s = "BruceWayneIsBatman"
Output: bruce wayne is batman
Explanation: The words in the string are
"Bruce", "Wayne", "Is", "Batman".
Ã¢â¬â¹Example 2:
Input: 
s = "You"
Output: you
Explanation: The only word in the string
is "You".
Your Task: 
You don't need to read input or print anything. Your task is to complete the function amendSentence() which takes the string s as input and returns a string with the stated amendments.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N) (for output string).
Constraints:
1<=Size of String <=10^{6}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N) (for output string).

Starter code:
#User function Template for python3

class Solution:

    def amendSentence(self, s):

        # code here

Solutions:
class Solution:

	def amendSentence(self, s):
		s1 = ''
		for i in s:
			if i.isupper():
				s1 = s1 + ' ' + i
			elif i.islower():
				s1 = s1 + i
		m1 = s1.lower()
		m2 = m1.strip()
		return m2


class Solution:

	def amendSentence(self, s):
		z1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		p = s[0]
		for i in range(1, len(s)):
			if s[i] in z1:
				p += ' ' + s[i]
			else:
				p += s[i]
		p = p.lower()
		return p


class Solution:

	def amendSentence(self, s):
		i = 0
		res = ''
		while i < len(s):
			temp = ''
			temp += s[i].lower()
			i += 1
			while i < len(s) and s[i].islower():
				temp += s[i]
				i += 1
			res += temp + ' '
		return res


class Solution:

	def amendSentence(self, s):
		L = [0]
		l = len(s)
		for i in range(1, l):
			if ord(s[i]) >= 65 and ord(s[i]) <= 91:
				L.append(i)
		L.append(len(s))
		s1 = s.lower()
		a = []
		for i in range(len(L) - 1):
			a.append(s1[L[i]:L[i + 1]])
		return ' '.join(a)


class Solution:

	def amendSentence(self, s):
		b = ''
		b += s[0].lower()
		for i in range(1, len(s)):
			if s[i].isupper():
				b += ' '
				b += s[i].lower()
			else:
				b += s[i]
		return b


class Solution:

	def amendSentence(self, s):
		if len(s) == 1:
			return s.lower()
		j = 0
		res = []
		for i in range(1, len(s)):
			if s[i].isupper():
				res.append(s[j:i].lower())
				j = i
		res.append(s[j:i + 1].lower())
		return ' '.join(res)


class Solution:

	def amendSentence(self, s):
		ind = 0
		st = 0
		en = 0
		arr = []
		for c in s:
			if c.isupper():
				if ind > 0:
					st = en
					en = ind
					arr.append([st, en])
				else:
					st = 0
					en = ind
			ind += 1
		arr.append([en, len(s)])
		ss = ''
		ind = 0
		for ar in arr:
			if ind == 0:
				ss = ss + s[ar[0]:ar[1]].lower()
			else:
				ss = ss + ' ' + s[ar[0]:ar[1]].lower()
			ind += 1
		return ss


class Solution:

	def amendSentence(self, s):
		temp = ''
		for i in range(len(s) - 1):
			if s[i].islower() and s[i + 1].isupper() or (s[i].isupper() and s[i + 1].isupper()):
				temp += s[i] + ' '
			else:
				temp += s[i]
		temp += s[-1]
		return temp.lower()


class Solution:

	def amendSentence(self, s):
		st = ''
		for i in s:
			if i.isupper():
				st += ' ' + i.lower()
			elif i.islower():
				st += i
		return st.strip()


class Solution:

	def amendSentence(self, s):
		new_str = ''
		for i in s:
			if i.isupper():
				new_str = new_str + ' ' + i
			else:
				new_str += i
		return new_str[1:].lower() if s[0].isupper() else new_str.lower()


class Solution:

	def amendSentence(self, s):
		res = s[0].lower()
		for x in s[1:]:
			if x.isupper():
				res = res + ' ' + x.lower()
			else:
				res += x
		return res


class Solution:

	def amendSentence(self, s):
		res = ''
		for char in s:
			if char.isupper():
				res += ' ' + char.lower()
			else:
				res += char
		return res.strip()


class Solution:

	def amendSentence(self, s):
		out = ''
		total = ''
		out += s[0].lower()
		for i in range(1, len(s)):
			if int(ord(s[i])) >= 65 and int(ord(s[i])) <= 90:
				out += ' '
				out += s[i].lower()
			else:
				out += s[i]
		return out


class Solution:

	def amendSentence(self, s):
		words = []
		i = 0
		while i < len(s) - 1:
			i += 1
			if s[i].isupper():
				words.append(s[:i])
				s = s[i:]
				i = 0
		words.append(s)
		return ' '.join(words).lower()


class Solution:

	def amendSentence(self, s):
		temp = str()
		for i in s:
			if i.isupper():
				temp += ' ' + i
			elif i.islower():
				temp += i
		res = temp.lower()
		res = res.strip()
		return res


class Solution:

	def amendSentence(self, s):
		new = ''
		new += s[0].lower()
		for i in range(1, len(s)):
			if s[i] == s[i].upper():
				new += ' ' + s[i].lower()
			else:
				new += s[i]
		return new


class Solution:

	def amendSentence(self, s):
		Cap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		ans = ''
		n = len(s)
		for i in range(n):
			if i == 0 and s[i] in Cap:
				ans += s[i].lower()
			elif s[i] in Cap:
				ans += ' ' + s[i].lower()
			else:
				ans += s[i]
		return ans


class Solution:

	def amendSentence(self, s):
		l = ''.join([' ' + i if i.isupper() else i for i in s]).strip().split()
		a = ''
		for i in l:
			a += ' ' + i.lower()
		return a.strip()


class Solution:

	def amendSentence(self, s):
		k = 0
		l1 = []
		i = 1
		while i < len(s):
			if s[i].isupper() == True:
				res = s[k:i]
				l1.append(res.lower())
				k = i
				i += 1
			else:
				i += 1
		if i == len(s):
			l1.append(s[k:i].lower())
		res1 = ''
		for i in l1:
			res1 += i
			res1 += ' '
		return res1


class Solution:

	def amendSentence(self, s):
		r = ''
		for i in s:
			if i.isupper():
				r += ' ' + i
			else:
				r += i
		r = r.strip()
		r = r.split()
		h = ''
		for i in r:
			h += i.lower() + ' '
		return h[:-1]


class Solution:

	def amendSentence(self, s):
		arr = list(s)
		ans = ''
		for v in arr:
			if v == v.upper():
				ans += ' ' + v.lower()
			else:
				ans += v
		return ans.strip()


class Solution:

	def amendSentence(self, s):
		new = ''
		pos = 0
		for i in range(0, len(s)):
			if s[i].isupper():
				word = s[pos:i]
				if word != '':
					new += word.lower() + ' '
				pos = i
		else:
			word = s[pos:i + 1]
			new += word.lower()
		return new


class Solution:

	def amendSentence(self, s):
		result = ''
		for elm in s:
			if elm.isupper():
				result += ' '
			result += elm.lower()
		return result.strip()


class Solution:

	def amendSentence(self, s):
		res = ' '
		for ch in s:
			if ch.isupper():
				res = res + ' ' + ch
			elif ch.islower():
				res = res + ch
		str1 = res.lower()
		str2 = str1.strip()
		return str2


class Solution:

	def amendSentence(self, s):
		arr = []
		curr = ''
		for i in range(len(s)):
			if not s[i].isupper():
				curr += s[i]
			else:
				if len(curr):
					arr.append(curr.lower())
				curr = s[i]
		arr.append(curr.lower())
		return ' '.join(arr)


class Solution:

	def amendSentence(self, s):
		sum = ''
		for i in s:
			if i.isupper():
				sum = sum + ' ' + i
			else:
				sum = sum + i
		sum = sum.lower()
		sum = sum.strip()
		return sum


class Solution:

	def amendSentence(self, s):
		k = ''
		for i in s:
			if i.isupper():
				k = k + ' ' + i
			else:
				k = k + i
		m = k.lower()
		m2 = m.strip()
		return m2


class Solution:

	def amendSentence(self, s):
		ans = ''
		ans += s[0].lower()
		k = s[1:len(s)]
		for i in k:
			if i.islower():
				ans += i
			elif i.isupper():
				ans = ans + ' ' + i.lower()
		return ans


class Solution:

	def amendSentence(self, s):
		val = s[0].lower()
		l = list(s[1:])
		for ele in l:
			if ele.isupper() == True:
				val = val + ' ' + ele.lower()
			else:
				val = val + ele
		return val


class Solution:

	def amendSentence(self, s):
		s1 = ''
		for i in range(len(s)):
			if s[i].isupper() == True and i != 0:
				s1 += ' '
				s1 += s[i]
			else:
				s1 += s[i]
		a = s1.lower()
		return a


class Solution:

	def amendSentence(self, s):
		k = ''
		for i in range(len(s)):
			if (ord(s[i]) >= 65 and ord(s[i]) <= 90) and len(k) == 0:
				k = chr(ord(s[i]) + 32)
			elif ord(s[i]) >= 65 and ord(s[i]) <= 90:
				k = k + ' ' + chr(ord(s[i]) + 32)
			else:
				k = k + s[i]
		return k


class Solution:

	def amendSentence(self, s):
		string = ''
		for (j, i) in enumerate(s):
			if i.isupper():
				if j != 0:
					string += ' '
				string += i.lower()
			else:
				string += i
		return string


class Solution:

	def amendSentence(self, s):
		x = ''
		for i in s:
			if ord(i) in range(65, 91):
				x += ' ' + i
			else:
				x += i
		y = x.lower()
		z = y.strip()
		return z


class Solution:

	def amendSentence(self, s):
		import re
		x = re.findall('[a-zA-Z][^A-Z]*', s)
		l = []
		for i in x:
			l.append(i.lower())
		return ' '.join(l)


class Solution:

	def amendSentence(self, s):
		s = s[0].upper() + s[1:] + 'W'
		r = ''
		for i in s:
			if i.isupper():
				r = r + ' ' + i.lower()
			else:
				r += i
		return r[1:-2]


class Solution:

	def amendSentence(self, s):
		a = ''
		for i in s:
			if 65 <= ord(i) <= 90:
				a = a + ' ' + i
			else:
				a = a + i
		b = a.lower()
		c = b.strip()
		return c


class Solution:

	def amendSentence(self, s):
		new_text = ''
		for (i, letter) in enumerate(s):
			if i and letter.isupper():
				new_text += ' '
			new_text += letter
		return new_text.lower()


class Solution:

	def amendSentence(self, s):
		x = ''
		for i in s:
			if i.isupper():
				x += '*' + i.lower()
			else:
				x += i
		x = x.split('*')
		p = ''
		for i in x:
			if not len(i) == 0:
				p += i + ' '
		p.strip()
		return p


class Solution:

	def getlower(self, ch):
		val = ord(ch) - ord('A')
		return chr(97 + val)

	def isupper(self, ch):
		return ch >= 'A' and ch <= 'Z'

	def amendSentence(self, s):
		n = len(s)
		ans = ''
		for i in range(n):
			if self.isupper(s[i]):
				if i != 0:
					ans += ' ' + self.getlower(s[i])
				else:
					ans += self.getlower(s[i])
			else:
				ans += s[i]
		return ans


from curses.ascii import islower

class Solution:

	def amendSentence(self, s):
		st = ''
		for i in range(0, len(s) - 1):
			st += s[i]
			if islower(s[i + 1]) == False:
				st += ' '
				continue
		st += s[len(s) - 1]
		return st.lower()


class Solution:

	def amendSentence(self, s):
		l1 = []
		if s[0].isupper():
			l1.append(s[0].lower())
		else:
			l1.append(s[0])
		for i in range(1, len(s)):
			if s[i].isupper():
				l1.append(' ')
				l1.append(s[i].lower())
			else:
				l1.append(s[i])
		return ''.join(l1)


class Solution:

	def amendSentence(self, s):
		t = ''
		for i in s:
			if i.isupper():
				t += ' ' + i.lower()
			else:
				t += i
		return t.lstrip()


class Solution:

	def amendSentence(self, s):
		outList = []
		word = ''
		i = 0
		for char in s:
			if i == 0:
				word += char.lower()
				i += 1
			elif char.isupper():
				outList.append(word)
				word = ''
				word += char.lower()
			else:
				word += char
		outList.append(word)
		outString = ''
		i = 0
		for str in outList:
			if i == 0:
				outString += str
				i += 1
			else:
				outString = outString + ' ' + str
		return outString


class Solution:

	def amendSentence(self, s):
		n = len(s)
		ans = ''
		prev = 0
		val = ord('a') - ord('A')
		ch = s[0]
		if ord(ch) - ord('A') >= 0 and ord(ch) - ord('A') < 26:
			pass
		else:
			s = chr(ord(s[prev]) - val) + s[1:]
		for i in range(1, n):
			ch = s[i]
			if ord(ch) - ord('A') >= 0 and ord(ch) - ord('A') < 26:
				ans = ans + chr(ord(s[prev]) + val) + s[prev + 1:i] + ' '
				prev = i
		ans = ans + chr(ord(s[prev]) + val) + s[prev + 1:]
		return ans.strip()
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.amendSentence(s))


class Solution:

	def amendSentence(self, s):
		s1 = ''
		for i in range(len(s)):
			if s[i].isupper():
				if i == 0:
					s1 += s[i].lower()
				else:
					s1 += ' '
					s1 += s[i].lower()
			else:
				s1 += s[i]
		return s1
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.amendSentence(s))


class Solution:

	def amendSentence(self, s):
		wordlist = ''
		for c in s:
			word = ''
			if c.isupper():
				word += ' ' + c.lower()
			else:
				word += c
			wordlist += word
		return wordlist.strip()
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.amendSentence(s))


class Solution:

	def amendSentence(self, s):
		replaced = ''
		for i in s:
			if i.isupper():
				replaced += ' ' + i.lower()
			else:
				replaced += i
		return replaced.strip()
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.amendSentence(s))


class Solution:

	def amendSentence(self, s):
		ans = ''
		ans += s[0].lower()
		k = s[1:]
		for i in k:
			if i.islower():
				ans += i
			elif i.isupper():
				ans = ans + ' ' + i.lower()
		return ans
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.amendSentence(s))


class Solution:

	def amendSentence(self, s):
		lst = [0]
		for i in range(1, len(s)):
			if ord(s[i]) >= ord('A') and ord(s[i]) <= ord('Z'):
				lst.append(i)
		if len(lst) == 1:
			return s.lower()
		str = ''
		for i in range(len(lst) - 1):
			start = lst[i]
			end = lst[i + 1]
			str += s[start:end] + ' '
			if i == len(lst) - 2:
				str += s[lst[-1]:]
		str = str.lower()
		return str
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		print(solObj.amendSentence(s))


class Solution:

	def amendSentence(self, s):
		s = list(s)
		for i in range(len(s)):
			if i == 0 and s[i].isupper():
				s[i] = s[i].lower()
			elif s[i].isupper():
				s[i] = ' ' + s[i].lower()
		return ''.join(s)


class Solution:

	def amendSentence(self, s):
		s_new = ''
		for i in s:
			if ord(i) >= 65 and ord(i) <= 91:
				s_new += ' '
				s_new += i.lower()
			else:
				s_new += i
		return s_new.lstrip()


class Solution:

	def amendSentence(self, s):
		os = ''
		for i in range(len(s)):
			if i == 0 and s[i].isupper():
				os = os + s[i].lower()
			elif s[i].isupper():
				os = os + ' ' + s[i].lower()
			else:
				os = os + s[i]
		return os


class Solution:

	def amendSentence(self, s):
		l1 = []
		word = s[0]
		for ch in s[1:]:
			if ch.isupper():
				l1.append(word.lower())
				word = ch
			else:
				word += ch
		l1.append(word.lower())
		ans = ' '.join(l1)
		return ans


class Solution:

	def amendSentence(self, s):
		res = ''
		for i in s:
			if i.isupper():
				res += '*' + i
			else:
				res += i
		arr = res.split('*')
		if arr[0] == '':
			arr.remove('')
		ans = ' '.join(arr)
		ans = ans.lower()
		return ans


class Solution:

	def amendSentence(self, s):
		n = len(s)
		if n == 1:
			return s.lower()
		ans = ''
		j = 0
		for i in range(n):
			if s[i].isupper():
				if ans == '':
					ans += s[j:i].lower()
				else:
					ans += ' '
					ans += s[j:i].lower()
				j = i
		ans += ' '
		ans += s[j:n].lower()
		return ans


class Solution:

	def amendSentence(self, s):
		l = []
		for i in range(len(s)):
			if s[i].isupper() == True:
				l.append(i)
		p = []
		if s[0].isupper() == False:
			p.append(s[:l[0]])
		for i in range(len(l) - 1):
			p.append(s[l[i]:l[i + 1]].lower())
		p.append(s[l[-1]:].lower())
		return ' '.join(p)


class Solution:

	def amendSentence(self, s):
		arr = []
		for i in s:
			if i.isupper():
				arr.append(' ')
				arr.append(i)
			if i.islower():
				arr.append(i)
		if arr[0] == ' ':
			arr.pop(0)
		arr = ''.join(map(str, arr))
		arr = arr.lower()
		return arr


class Solution:

	def amendSentence(self, s):
		sList = list(s)
		for i in range(0, len(sList)):
			if sList[i].isupper():
				if i == 0:
					sList[i] = sList[i].lower()
				else:
					sList[i] = ' ' + sList[i].lower()
		return ''.join(sList)


class Solution:

	def amendSentence(self, s):
		st = ''
		for c in s:
			if c.isupper():
				if st != '':
					st += ' '
				c = c.lower()
			st += c
		return st


class Solution:

	def amendSentence(self, s):
		k = ''
		for i in range(len(s)):
			if s[i].isupper() and len(k) == 0:
				k = k + s[i].lower()
			elif s[i].isupper() and len(k) > 0:
				k = k + ' '
				k = k + s[i].lower()
			elif s[i].islower():
				k = k + s[i]
		return k


class Solution:

	def amendSentence(self, s):
		n = len(s)
		p = ''
		p = p + s[0].lower()
		for i in range(1, n):
			if s[i].isupper():
				p = p + ' '
				p = p + s[i].lower()
				continue
			p = p + s[i]
		return p