Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 0c4ad38

Browse files
committed
Question 2 is done
1 parent 9fa106b commit 0c4ad38

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

CA1/Question2.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def is_palindrome(s):
2+
return s == s[::-1]
3+
4+
def palindrome_exists(string) :
5+
characters = set()
6+
found = False
7+
for char in string :
8+
if not char in characters :
9+
characters.add(char)
10+
j = 0
11+
while j < len(string) + 1:
12+
new_string = string[:j] + char + string[j:]
13+
if is_palindrome(new_string) :
14+
found = True
15+
break
16+
j += 1
17+
return found
18+
19+
def main() :
20+
commands = int(input())
21+
i = 0
22+
while i < commands :
23+
string = input()
24+
if string == "" :
25+
continue
26+
if palindrome_exists(string) == True:
27+
print("YES")
28+
else :
29+
print("NO")
30+
i += 1
31+
32+
main()

0 commit comments

Comments
 (0)