We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8168d52 commit deb6c15Copy full SHA for deb6c15
Introductory-Problems/Repetitions.py
@@ -1,14 +1,20 @@
1
-sq = [i for i in input().split()] # ACCCGTC
2
-s = set([sq[0]])
3
-max_val = 1
4
-cnt = 0
5
-for i in range(1, len(sq)):
6
- if len(s) == 1:
7
- cnt += 1
8
- max_val = max(max_val, cnt)
9
- s.add(sq[i])
+# I, here, have tried to implement this with a stack
+# the idea is to push consequtive chars in a stack a keep count of it
+
+sq = [i for i in input().split()][0] # ACCCGTC
+s = []
+maxx = 1
+current_letter = sq[0]
+for i in range(0, len(sq)):
+ if sq[i] == current_letter:
10
+ s.append(sq[i])
11
+ maxx = max(maxx, len(s))
12
else:
- s.pop(0)
- cnt = 0
13
-print(max_val) # wrong ans
+ current_letter = sq[i]
14
+ s.clear()
15
16
17
18
19
+print(maxx) # wrong ans
20
0 commit comments