practivceAlgorithm/codeforce

[codeforce][Python] #719 A.Do Not Be Distracted!

findTheValue 2021. 10. 17. 18:54

연속되지 않으면서 같은 문자가 나오면 NO

 

import sys
input = sys.stdin.readline

for test in range(int(input())):
    n = int(input())
    a = list(input().rstrip())
    char_set = {a[0]: True}
    for i in range(1, n):
        if a[i - 1] != a[i]:
            if a[i] in char_set:
                print('NO')
                break
            else:
                char_set[a[i]] = True
    else:
        print('YES')