MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / repeat_counts

Function repeat_counts

CSES_Problems/Repetitions/solution.py:1–14  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

1def repeat_counts(n):
2 if len(n)==1: # checking for the length of n. If it is 1 then returns 1
3 return 1
4 maxx=c=0 # initializing maxx and c as 0. maxx is used for maximum check and c is used for counting
5 for i in range(1,len(n)):
6 if n[i-1]==n[i]: # check if the element previous the current element is same or not
7 c+=1
8 if n[i-1]!=n[i] or i==len(n)-1: # check if the element previous is not same as the present one or the present index is the last index
9 c+=1 # count increased by 1 here because it is still taking account of the previous element
10 if maxx<c: # checks if c is the maximum or not
11 maxx=c
12 c=0 # initializes c back to 0 and there the next check goes on
13
14 return maxx
15
16
17n = input()

Callers 1

solution.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected