-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday96.py
More file actions
34 lines (26 loc) · 676 Bytes
/
day96.py
File metadata and controls
34 lines (26 loc) · 676 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
27
28
29
30
31
32
33
34
#!/bin/python3
import sys
from collections import Counter
def is_palindrome(s):
return s == s[::-1]
def palindromeIndex(s):
ret = -1
lens = len(s)
ind = 0
if is_palindrome(s):
return ret
while ind < lens//2:
if s[ind] != s[lens-ind-1]:
if s[ind+1] == s[lens-ind-1] and s[ind+2] == s[lens-ind-2]:
ret = ind
break
else:
ret = lens-ind-1
break
ind += 1
return ret
q = int(input().strip())
for a0 in range(q):
s = input().strip()
result = palindromeIndex(s)
print(result)