You have given a non-empty string. This string can consist of lowercase and uppercase english alphabets. Convert the string into an alternating sequence of lowercase and uppercase characters without changing the character at the 0th index.
Example 1:
Input:
S = "geeksforgeeks"
Output: gEeKsFoRgEeKs
Explanation: The first character is kept
unchanged whereas all the characters are
arranged in alternating order of lowercase
and uppercase.
Ã¢â¬â¹Example 2:
Input: 
S = "Geeksforgeeks"
Output: GeEkSfOrGeEkS
Explanation: The first character is kept
unchanged whereas all the characters are
arranged in alternating order of lowercase
and uppercase.
Your Task:
You don't need to read input or print anything. Your task is to complete the function getCrazy() which takes the string S as input and returns the resultant string by making the stated modifications.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1<=|S|<=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:



    def getCrazy(self, S):

        # code here

Solutions:
class Solution:

	def getCrazy(self, S):
		if S[0].islower():
			flag = True
		if S[0].isupper():
			flag = False
		ans = ''
		for i in range(len(S)):
			if flag:
				ans += S[i].lower()
			else:
				ans += S[i].upper()
			flag = 1 - flag
		return ans


class Solution:

	def getCrazy(self, S):
		g = S[0]
		if S[0].islower() == True:
			for i in range(1, len(S)):
				if i % 2 != 0:
					g += S[i].upper()
				else:
					g += S[i].lower()
		else:
			for i in range(1, len(S)):
				if i % 2 != 0:
					g += S[i].lower()
				else:
					g += S[i].upper()
		return g


class Solution:

	def getCrazy(self, S):
		temp = S[0]
		if S[0].isupper():
			for i in range(1, len(S)):
				if i % 2 == 0:
					temp += S[i].upper()
				else:
					temp += S[i].lower()
		else:
			for i in range(1, len(S)):
				if i % 2 == 0:
					temp += S[i].lower()
				else:
					temp += S[i].upper()
		return temp


class Solution:

	def getCrazy(self, S):
		o = 0 if S[0] == S[0].upper() else 1
		s = ''
		for i in range(0, len(S)):
			if i % 2 == o:
				s += S[i].upper()
			else:
				s += S[i].lower()
		return s


class Solution:

	def getCrazy(self, S):
		oddeven = 0 if S[0] == S[0].upper() else 1
		str = ''
		for i in range(0, len(S)):
			if i % 2 == oddeven:
				str += S[i].upper()
			else:
				str += S[i].lower()
		return str


class Solution:

	def getCrazy(self, s):
		l = list(s)
		n = len(s)
		f = ''
		if s[0].isupper():
			for i in range(0, n, 2):
				l[i] = l[i].upper()
			for i in range(1, n, 2):
				l[i] = l[i].lower()
			for i in l:
				f += i.strip()
		else:
			for i in range(0, n, 2):
				l[i] = l[i].lower()
			for i in range(1, n, 2):
				l[i] = l[i].upper()
			for i in l:
				f += i.strip()
		return f


class Solution:

	def getCrazy(self, s):
		t = ''
		l = s[0].isupper()
		for i in range(0, len(s)):
			if l:
				t = t + s[i].upper()
				l = False
			else:
				t = t + s[i].lower()
				l = True
		return t


class Solution:

	def getCrazy(self, S):
		s = ''
		x = len(S)
		if S[0].islower():
			for i in range(x):
				if i % 2 == 0:
					s = s + S[i].lower()
				else:
					s = s + S[i].upper()
			return s
		else:
			for i in range(x):
				if i % 2 == 0:
					s = s + S[i].upper()
				else:
					s = s + S[i].lower()
			return s


class Solution:

	def getCrazy(self, S):
		oe = 0 if S[0] == S[0].upper() else 1
		ans = ''
		for i in range(0, len(S)):
			if i % 2 == oe:
				ans += S[i].upper()
			else:
				ans += S[i].lower()
		return ans


class Solution:

	def getCrazy(self, S):
		ans = S[0]
		for j in range(1, len(S)):
			if ans[-1].islower():
				ans += S[j].upper()
			else:
				ans += S[j].lower()
		return ans


class Solution:

	def getCrazy(self, S):
		ans = S[0]
		for i in range(len(S)):
			if S[0].isupper():
				if i % 2 == 0 and i > 0:
					ans = ans + S[i].upper()
				elif i % 2 != 0 and i > 0:
					ans = ans + S[i].lower()
			elif S[0].islower():
				if i % 2 != 0 and i > 0:
					ans = ans + S[i].upper()
				elif i % 2 == 0 and i > 0:
					ans = ans + S[i].lower()
		return ans


class Solution:

	def getCrazy(self, S):
		upper_idx = 1 if S[0] == S[0].upper() else 0
		result = ''
		for i in range(1, len(S) + 1):
			if i % 2 == upper_idx:
				result += S[i - 1].upper()
			else:
				result += S[i - 1].lower()
		return result


class Solution:

	def getCrazy(self, S):
		l = 0 if S[0] == S[0].upper() else 1
		k = ''
		for i in range(0, len(S)):
			if i % 2 == l:
				k += S[i].upper()
			else:
				k += S[i].lower()
		return k


class Solution:

	def getCrazy(self, S):
		string = list(S)
		isupper = not string[0].isupper()
		n = len(string)
		for i in range(1, n):
			if isupper:
				string[i] = string[i].upper()
				isupper = not isupper
			else:
				string[i] = string[i].lower()
				isupper = not isupper
		return ''.join(string)


class Solution:

	def getCrazy(self, S):
		b = ''
		len_s = len(S)
		x = S[0]
		if S[0].islower():
			for i in range(1, len_s):
				if i % 2 != 0:
					x += S[i].upper()
				else:
					x += S[i].lower()
		else:
			for i in range(1, len_s):
				if i % 2 == 0:
					x += S[i].upper()
				else:
					x += S[i].lower()
		return x


class Solution:

	def getCrazy(self, S):
		r = S[0]
		upper = r.isupper()
		for i in S[1:]:
			if upper:
				r += i.lower()
				upper = False
			else:
				upper = True
				r += i.upper()
		return r


class Solution:

	def getCrazy(self, S):
		z = list(S)
		for i in range(len(z)):
			if z[0].isupper():
				if i % 2 == 0:
					z[i] = z[i].upper()
				else:
					z[i] = z[i].lower()
			elif i % 2 != 0:
				z[i] = z[i].upper()
			else:
				z[i] = z[i].lower()
		return ''.join(z)


class Solution:

	def getCrazy(self, S):
		new = ''
		for i in range(len(S)):
			if S[0].islower():
				if i % 2 == 0:
					new += S[i].lower()
				else:
					new += S[i].upper()
			elif i % 2 == 0:
				new += S[i].upper()
			else:
				new += S[i].lower()
		return new


class Solution:

	def getCrazy(self, S):
		S = list(map(str, S))
		n = len(S)
		st = ''
		a = 0
		if S[0].isupper():
			a = 1
		if a == 1:
			for i in range(0, n):
				if i % 2 == 0:
					S[i] = S[i].upper()
					st = st + S[i]
				else:
					S[i] = S[i].lower()
					st = st + S[i]
		elif a == 0:
			for i in range(0, n):
				if i % 2 == 0:
					S[i] = S[i].lower()
					st = st + S[i]
				else:
					S[i] = S[i].upper()
					st = st + S[i]
		return st
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.getCrazy(S))


class Solution:

	def getCrazy(self, S):
		lst = list(map(str, S))
		flag = False
		if lst[0].islower():
			flag = True
		if flag:
			for i in range(len(lst)):
				if i % 2 == 0:
					lst[i] = lst[i].lower()
				else:
					lst[i] = lst[i].upper()
		else:
			for i in range(len(lst)):
				if i % 2 == 0:
					lst[i] = lst[i].upper()
				else:
					lst[i] = lst[i].lower()
		return ''.join(lst)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.getCrazy(S))


class Solution:

	def getCrazy(self, S):
		if S[0].islower():
			s = ''
			for i in range(len(S)):
				if i % 2 == 0:
					s += S[i].lower()
				else:
					s += S[i].upper()
		else:
			s = ''
			for i in range(len(S)):
				if i % 2 == 0:
					s += S[i].upper()
				else:
					s += S[i].lower()
		return s
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.getCrazy(S))


class Solution:

	def getCrazy(self, S):
		lst = list(S)
		count = 0
		if lst[0].islower():
			for itr in range(1, len(lst)):
				if itr % 2 == 0:
					lst[itr] = lst[itr].lower()
				else:
					lst[itr] = lst[itr].upper()
		else:
			for itr in range(1, len(lst)):
				if itr % 2 == 0:
					lst[itr] = lst[itr].upper()
				else:
					lst[itr] = lst[itr].lower()
		return ''.join(lst)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.getCrazy(S))


class Solution:

	def getCrazy(self, S):
		if S[0].isupper():
			c = 1
		else:
			c = 0
		t = ''
		t += S[0]
		n = len(S)
		for i in range(1, n):
			if i % 2 == c:
				t += S[i].lower()
			else:
				t += S[i].upper()
		return t
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.getCrazy(S))


class Solution:

	def getCrazy(self, S):
		x = S[0]
		ans = S[0]
		flag = x.islower()
		for i in range(1, len(S)):
			if flag == True:
				ans += S[i].upper()
				flag = False
			else:
				ans += S[i].lower()
				flag = True
		return ans
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		S = input()
		solObj = Solution()
		print(solObj.getCrazy(S))


class Solution:

	def getCrazy(self, S):
		n = len(S)
		st = ''
		if S[0].isupper():
			for i in range(0, n):
				if i % 2 == 0:
					st = st + S[i].upper()
				else:
					st = st + S[i].lower()
		else:
			for i in range(0, n):
				if i % 2 != 0:
					st = st + S[i].upper()
				else:
					st = st + S[i].lower()
		return st


class Solution:

	def getCrazy(self, S):
		a = ''
		a = a + S[0]
		if ord(S[0]) >= 65 and ord(S[0]) <= 90:
			for i in range(1, len(S)):
				if i % 2 == 0:
					if ord(S[i]) >= 65 and ord(S[i]) <= 90:
						a = a + S[i]
					else:
						a = a + chr(ord(S[i]) - 32)
				elif ord(S[i]) >= 97 and ord(S[i]) <= 122:
					a = a + S[i]
				else:
					a = a + chr(ord(S[i]) + 32)
		else:
			for i in range(1, len(S)):
				if i % 2 != 0:
					if ord(S[i]) >= 65 and ord(S[i]) <= 90:
						a = a + S[i]
					else:
						a = a + chr(ord(S[i]) - 32)
				elif ord(S[i]) >= 97 and ord(S[i]) <= 122:
					a = a + S[i]
				else:
					a = a + chr(ord(S[i]) + 32)
		return a


class Solution:

	def getCrazy(self, s):
		n = len(s)
		ans = ''
		ch = s[0]
		if ch.isupper():
			for i in range(n):
				if i % 2 == 0:
					ch = s[i]
					ans += ch.upper()
				else:
					ch = s[i]
					ans += ch.lower()
		else:
			for i in range(n):
				if i % 2 == 0:
					ch = s[i]
					ans += ch.lower()
				else:
					ch = s[i]
					ans += ch.upper()
		return ans


class Solution:

	def getCrazy(self, S):
		s = list(S)
		a = s[0]
		for i in range(1, len(s)):
			if a.islower():
				s[i] = s[i].upper()
				a = s[i]
			else:
				s[i] = s[i].lower()
				a = s[i]
		return ''.join(s)


class Solution:

	def getCrazy(self, S):
		s2 = S[0]
		if S[0].isupper():
			for i in range(1, len(S)):
				if i % 2 == 0:
					s2 = s2 + S[i].upper()
				if i % 2 != 0:
					s2 = s2 + S[i].lower()
		if S[0].islower():
			for i in range(1, len(S)):
				if i % 2 == 0:
					s2 = s2 + S[i].lower()
				if i % 2 != 0:
					s2 = s2 + S[i].upper()
		return s2


class Solution:

	def getCrazy(self, S):
		k = ''
		if S[0].islower():
			for i in range(len(S)):
				if i % 2 == 0:
					b = S[i].lower()
					k += b
				else:
					b = S[i].upper()
					k += b
		else:
			for i in range(len(S)):
				if i % 2 == 0:
					b = S[i].upper()
					k += b
				else:
					b = S[i].lower()
					k += b
		return k


class Solution:

	def getCrazy(self, S):
		a = list(S)
		if a[0].isupper() == True:
			for i in range(0, len(a), 2):
				a[i] = a[i].upper()
			for i in range(1, len(a), 2):
				a[i] = a[i].lower()
		else:
			for i in range(0, len(a), 2):
				a[i] = a[i].lower()
			for i in range(1, len(a), 2):
				a[i] = a[i].upper()
		return ''.join(a)


class Solution:

	def getCrazy(self, S):
		l = len(S)
		i = 0
		news = S[0]
		if l == 1:
			return S
		if S[0].isupper():
			i = 1
		for x in range(1, l):
			if i == 1:
				news += S[x].lower()
				i = 0
			else:
				news += S[x].upper()
				i = 1
		return news