Most simultaneously repeated character in string

In this program, we will take a string as input and find the most simultaneously repeated character in the input string.

Steps to solve the program
  1. Take a string as input.
  2. Create two variables to find the most simultaneously repeated character in a string.
  3. Using For loop with the range() function find whether a character is repeated in the string or not.
  4. If yes then, count how many times it has been repeated.
  5. Print the most simultaneously repeated character in a string.
				
					#Input string
str1 = "Helllllo ffdfdas sdfsfsd sssfdddd"
max_repeat_count = 0
max_repeat_char = ''

temp = 1
for i in range(len(str1)-1):
    if str1[i] == str1[i+1]:
        temp = temp + 1
        if temp > max_repeat_count:
            max_repeat_count = temp
            max_repeat_char = str1[i]
    else:
        temp = 1

#Printing output
print("Max repeated char :", max_repeat_char,
      "\nMax repeated count :", max_repeat_count)
				
			

Output :

				
					Max repeated char : l 
Max repeated count : 5
				
			

Find the longest and smallest word in the input string.

calculate the length of a string with loop logic.

Leave a Comment