-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcontest p5
More file actions
41 lines (40 loc) · 941 Bytes
/
contest p5
File metadata and controls
41 lines (40 loc) · 941 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
35
36
37
38
39
40
41
def StringChallenge(strParam):
left = 0
right=len(strParam)-1
pal=""
c=0
while left<=right:
if strParam[left]==strParam[right]:
left+=1
right-=1
else:
if strParam[right]==strParam[left+1]:
c+=1
pal+=strParam[left]
left+=1
elif strParam[right]==strParam[left+2]:
c+=2
pal+=strParam[left]+strParam[left+1]
left+=2
elif strParam[left]==strParam[right-1]:
c+=1
pal+=strParam[right]
right-=1
elif strParam[left]==strParam[right-2]:
c+=2
pal+=strParam[right-1]+strParam[right]
right-=2
elif strParam[left+1]==strParam[right-1]:
c+=2
pal+=strParam[left]+strParam[right]
right-=1
left+=1
else:
print(pal)
return "not possible"
if c>2:
print(pal)
return "not possible"
if c==0:
return "palindrome"
return pal