Can anyone write the shortest code for a palindrome ? Also try and do it for words like HANNAH . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone write the shortest code for a palindrome ? Also try and do it for words like HANNAH .

Time constraint is 1s only and palindrome is a number that is same from front to back.

24th Sep 2017, 3:12 AM
Aayush Malhotra
4 Answers
+ 7
I'm trying to find a shorter version... But if you use python, the code will just be a one liner...
24th Sep 2017, 3:42 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
// C++ Code. // Time taken for 52 letter string - 0.04s // Number of lines - 11 #include<iostream> #include<string> #include<algorithm> using namespace std; int main() { string data, data2; getline(cin,data); data2 = data; reverse(data2.begin(),data2.end()); if(data2 == data) cout<<"Yes"; else cout<<"No"; }
24th Sep 2017, 3:41 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
// Python Code. // Time taken for 52 letter string - 0.00s // Number of lines - 2 a = raw_input() print(str(a)==str(a)[::-1])
24th Sep 2017, 3:53 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
- 2
print((lambda a:a==a[::-1])(input()))
13th Jan 2018, 8:58 AM
VcC
VcC - avatar