EPS/2024/04/08-04-24/b.py

30 lines
614 B
Python
Raw Permalink Normal View History

2024-04-15 13:45:30 +02:00
def main():
length = int(input())
st = input()
counts = [(0, 0) for i in range(len(st)+1)]
found = set()
cur = 0
for i in range(len(st)):
c = st[i]
if c not in found:
found.add(c)
cur += 1
counts[i+1] = (cur, counts[i][1])
found = set()
cur = 0
for i in range(len(st)-1, -1, -1):
c = st[i]
if c not in found:
found.add(c)
cur += 1
counts[i] = (counts[i][0], cur)
# print(counts)
return max([(c[0]+c[1]) for c in counts])
for _ in range(int(input())):
print(main())