write a program to check whether it is a palindrome or not ?
Input : 12321
output : it is a palindrome
input : mam
input : 12345
output: not a palindrome
Discussion posts and replies are publicly visible
Atleast give it a try before posting here.
a!localVariables( local!input: char(code(ri!input)), local!reverse: reverse(local!input), and(local!reverse = local!input) )
I tried this logic, its not working for number like 121, 1331.
Then try it again. It still works perfectly for any palindrome.
/* two pointer approach */
a!localVariables( local!text: "12121", local!count: ceiling(len(local!text) / 2), and( a!forEach( items: enumerate(local!count), expression: local!text[fv!index] = local!text[len(local!text) - fv!index + 1] ) ))