-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1287A.py
More file actions
26 lines (22 loc) · 718 Bytes
/
1287A.py
File metadata and controls
26 lines (22 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Name: Angry Students
# Link: https://codeforces.com/problemset/problem/1287/A
# Method: Linear scan, see last "A"ngry one
# Time: O(n)
# Space: O(1)
# Difficulty: A
if __name__ == "__main__":
tests = int(input())
for _ in range(tests):
cn = int(input())
s_arr = input()
prev_anv = -1
max_dist = 0
for i, indiv in enumerate(s_arr):
if indiv == "A":
if prev_anv != -1:
max_dist = max(max_dist, i - prev_anv - 1)
prev_anv = max(prev_anv, i)
# At least one angry
if prev_anv != -1:
max_dist = max(max_dist, cn - prev_anv - 1)
print(max_dist)