Given a Sentence S of length N containing only english alphabet characters, your task is to write a program that converts the given sentence to Snake Case sentence. Snake case is the practice of writing compound words or phrases in which the elements are separated with one underscore character (_) and no spaces, and the first letter of each word written in lowercase. For ease keep all the characters in lowercase.
Note: The given sentence will not start with a Whitespace.
Example 1: 
Input: 
N = 14
S = "Geeks ForGeeks"
Output: "geeks_forgeeks"
Explanation: All upper case characters are
converted to lower case and the whitespace
characters are replaced with underscore '_'.
Example 2: 
Input: 
N = 21
S = "Here comes the garden"
Output: "here_comes_the_garden"
Explanation: All upper case characters are
converted to lower case and the whitespace 
characters are replaced with underscore '_'.
Your Task:
You don't need to read input or print anything. Your task is to complete the function snakeCase() which takes N and a String S as input parameters and returns the converted string .
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
class Solution:
    def snakeCase(self, S , n):
        # code here

Solutions:
class Solution:

	def snakeCase(self, S, n):
		str1 = ''
		for i in range(n):
			if S[i].isupper() == True:
				str1 = str1 + S[i].lower()
			elif S[i] == ' ':
				str1 = str1 + '_'
			else:
				str1 = str1 + S[i]
		return str1


class Solution:

	def snakeCase(self, S, n):
		S = S.lower().replace(' ', '_')
		return S


class Solution:

	def snakeCase(self, S, n):
		s = ''
		for i in range(len(S)):
			if S[i] == ' ':
				s += '_'
			else:
				s += S[i]
		return s.lower()


class Solution:

	def snakeCase(self, S, n):
		S = '_'.join(S.split(' '))
		return S.lower()


class Solution:

	def snakeCase(self, S, n):
		d = ''
		for i in S:
			if i.isupper() == True:
				d += i.lower()
			elif i.isspace() == True:
				d += '_'
			else:
				d += i
		return d


class Solution:

	def snakeCase(self, S, n):
		m = S.lower()
		k = list(map(str, str(m)))
		for i in range(0, n):
			if k[i] == ' ':
				k[i] = '_'
		r = str(''.join(map(str, k)))
		return r


class Solution:

	def snakeCase(self, S, n):
		s = S.lower()
		k = s.replace(' ', '_')
		return k


class Solution:

	def snakeCase(self, S, n):
		p = S.lower()
		q = p.replace(' ', '_')
		return q


class Solution:

	def snakeCase(self, S, n):
		s = list(S)
		for i in range(len(s)):
			if s[i].isupper():
				s[i] = s[i].lower()
			elif s[i] == ' ':
				s[i] = '_'
		return ''.join(s)


class Solution:

	def snakeCase(self, S, n):
		l = ''
		for i in S:
			if i == ' ':
				l = l + '_'
			else:
				l = l + i
		return l.lower()


class Solution:

	def snakeCase(self, s, n):
		s = s.lower()
		s = s.replace(' ', '_')
		return s


class Solution:

	def snakeCase(self, s, n):
		r = ''
		for i in range(len(s)):
			if s[i].isupper():
				x = s[i].lower()
				r += x
			elif s[i] == ' ':
				x = '_'
				r += x
			else:
				r += s[i]
		return r


class Solution:

	def snakeCase(self, S, n):
		k = S.lower()
		s = ''
		if ' ' in S:
			s = k.replace(' ', '_')
		else:
			s = k
		return s


class Solution:

	def snakeCase(self, S, n):
		x = S.lower()
		y = x.replace(' ', '_')
		return y


class Solution:

	def snakeCase(self, S, n):
		temp = ''
		for e in S:
			if e == ' ':
				temp += '_'
			else:
				temp += e.lower()
		return temp


class Solution:

	def snakeCase(self, S, n):
		s1 = ''
		for i in range(0, n):
			if S[i] != ' ':
				s1 = s1 + S[i].lower()
			else:
				s1 = s1 + '_'
		return s1


class Solution:

	def snakeCase(self, S, n):
		if len(S) == n:
			output = S.lower()
			return output.replace(' ', '_')


class Solution:

	def snakeCase(self, S, n):
		a = S.replace(' ', '_')
		a = [i for i in a]
		s = []
		for i in a:
			s.append(i.lower())
		return ''.join(s)


class Solution:

	def snakeCase(self, S, n):
		S = S.split(' ')
		res = ''
		for i in S:
			i = i.lower()
			res += i + '_'
		return res[:len(res) - 1]


class Solution:

	def snakeCase(self, S, n):
		S = S.lower()
		ans = ''
		for ch in S:
			if ch == ' ':
				ans += '_'
			else:
				ans += ch
		return ans


class Solution:

	def snakeCase(self, S, n):
		v = 'aeiou'
		vc = 0
		cc = 0
		new_s = ''
		for i in S:
			if i in v:
				vc += 1
				new_s += i.lower()
			elif i.isspace():
				new_s += '_'
			else:
				cc += 1
				new_s += i.lower()
		return new_s


class Solution:

	def snakeCase(self, S, n):
		Sum = ''
		for item in S:
			if item.isupper():
				Sum += item.lower()
			else:
				Sum += item
		return Sum.replace(' ', '_')


class Solution:

	def snakeCase(self, S, n):
		S = S.lower()
		for x in S:
			if x == ' ':
				S = S.replace(x, '_')
		return S


class Solution:

	def snakeCase(self, S, n):
		i = S.lower()
		d = i.replace(' ', '_')
		return d


class Solution:

	def snakeCase(self, S, n):
		self.s = S
		self.n = n
		s1 = ''
		for i in range(self.n):
			if self.s[i].isupper():
				s1 = s1 + self.s[i].lower()
			elif self.s[i] == ' ':
				s1 = s1 + '_'
			else:
				s1 = s1 + self.s[i]
		return s1


class Solution:

	def snakeCase(self, S, n):
		a = S.lower()
		ans = ''
		for i in a:
			if i == ' ':
				ans = ans + '_'
			else:
				ans = ans + i
		return ans


class Solution:

	def snakeCase(self, s, n):
		a = s.replace(' ', '_')
		b = a.lower()
		return b


class Solution:

	def snakeCase(self, S, n):
		s = S.lower()
		t = ''
		for i in s:
			if i == ' ':
				t += '_'
			else:
				t += i
		return t


class Solution:

	def snakeCase(self, S, n):
		k = ''
		for i in S:
			if i == ' ':
				k += '_'
			elif i.islower():
				k += i
			else:
				k += i.lower()
		return k


class Solution:

	def snakeCase(self, S, n):
		ans = S.lower()
		for i in range(n):
			if ans[i] == ' ':
				ans = ans[:i] + '_' + ans[i + 1:]
		return ans


class Solution:

	def snakeCase(self, s, n):
		s = s.lower()
		s = s.split(' ')
		return '_'.join(s)


class Solution:

	def snakeCase(self, S, n):
		l = S.lower()
		st = ''
		for i in l:
			if i != ' ':
				st += i
			elif i == ' ':
				st += '_'
		return st


class Solution:

	def snakeCase(self, S, n):
		new_s = ''
		upper = 0
		for c in S:
			if c == ' ':
				new_s += '_'
			elif c.isupper():
				new_s += chr(97 + ord(c) - 65)
			else:
				new_s += c
		return new_s


class Solution:

	def snakeCase(self, S, n):
		d = ''
		for i in range(n):
			if S[i] == ' ':
				d += '_'
			else:
				d += S[i].lower()
		return d


class Solution:

	def snakeCase(self, S, n):
		s = ''
		for i in S:
			if i.isupper():
				i = i.lower()
			if i == ' ':
				i = '_'
			s += i
		return s


class Solution:

	def snakeCase(self, S, n):
		S = S.casefold()
		for i in range(n):
			if S[i] == ' ':
				S = S[0:i] + '_' + S[i + 1:]
		return S


class Solution:

	def snakeCase(self, S, n):
		st = ''
		for i in S:
			if i.islower():
				st += i
			if i.isupper():
				st += i.lower()
			if i == ' ':
				st += '_'
		return st


class Solution:

	def snakeCase(self, S, n):
		s = ''
		S = S.replace(' ', '_')
		for i in range(n):
			if ord(S[i]) >= 65 and ord(S[i]) <= 90:
				s += chr(ord(S[i]) + 32)
			else:
				s += S[i]
		return s