File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''
2
+ Make Palindrome
3
+ Given a string S of length l and you have to covert that into palindrome using the same string. You will
4
+ also given a number N, if N is 0 you have a make the palindrome of length 2xl, if N is 1 then the final
5
+ length will be 2xl - 1.
6
+
7
+ A string is said to be a palindrome if the string read from left to right is equal to the string read
8
+ from right to left.
9
+
10
+ If the length of the given string is 1, you don't have to do anything, just return the string. As every
11
+ letter is a palindrome of length 1.
12
+
13
+ Input-1
14
+ asdf
15
+
16
+ 0
17
+
18
+ Output-1
19
+ asdffdsa
20
+
21
+ Input-2
22
+ asdf
23
+
24
+ 1
25
+
26
+ Output-2
27
+ asdfdsa
28
+
29
+ '''
30
+ s = input ()
31
+ n = int (input ())
32
+ if n == 0 and len (s )> 1 :
33
+ print (s + s [:- (len (s )+ 1 ):- 1 ])
34
+ elif n == 1 and len (s )> 1 :
35
+ print (s + s [- 2 :- (len (s )+ 1 ):- 1 ])
36
+ if (len (s )== 1 ):
37
+ print (s )
You can’t perform that action at this time.
0 commit comments