https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWRKNev6fqYDFAV8
T = int(input())
for tc in range(1, T+1):
word = input()
N = len(word)
result = 0
sorted_word = sorted(word)
for i in range(N):
for j in range(i + 1, N + 1):
if sorted_word[i:j] == sorted_word[i:j][::-1]:
result += 1
print('#{} {}'.format(tc, result))
sorted() 메서드를 이용하면 문자열 'abcabc'를 'aabbcc' 형태로 정렬할 수 있다. 이렇게 정렬해서 팰린드롬을 카운트 했을 때 팰린드롬의 최댓값을 찾을 수 있다. 처음에 나는 'abcabc'를 'abccba'로 바꿀 방법만 생각했었는데 이렇게 풀 경우 엣지 케이스가 생긴다.
ex) 만약 한 문자가 3번 이상 등장한다면 처음에는 'a@@@@@' 두 번째 등장했을 때에는 'a@@@@a' 세 번째 등장했을 때는 'aa@@@a'의 형태로 들어가게 되는데 이 경우 팰린드롬의 최댓값을 정확히 셀 수 없음