human
Count substrings made up of a single distinct character | Function to count the number of substrings made up of a single distinct character.
Stores the required count.
Stores the count of substrings possible by using current character.
Stores the previous character.
Traverse the string.
If current character is same as the previous character.
Increase count of substrings possible with current character.
Reset count of substrings possible with current character.
Update count of substrings.
Update previous character.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to count substrings made up of a single distinct character and the other steps required.
 def countSubstrings ( s ) :
	ans = 0
	subs = 1
	pre = ' '
	for i in s :
		if pre == i :
			subs += 1
		else :
			subs = 1
		ans += subs
		pre = i
	print ( ans )
s = ' geeksforgeeks '
countSubstrings ( s )