Questions tagged [palindrome]

A word, phrase, number, or other sequence of units that may be read the same way in either direction, forward or backward.

A word, phrase, number, or other sequence of units that may be read the same way in either direction, forward or backward.

Spacing and punctuation is generally ignored when attempting to determine whether the potential palindrome under consideration is in fact a palindrome. One such example is:

I, madam, I, made radio - so I dared! Am I mad? Am I?

(from http://www.joe-ks.com/palindromes.htm)

1763 questions
4
votes
1 answer

How do I write a palindrome program while using different lists?

I tried to write a palindrome program by using lists. However, I have to use difference lists and output should be: The ith element of the list is the same of (n-i+1)th element of the list and n is the length of the list. For example, [a,X,c,b,Y]…
limonik
  • 499
  • 1
  • 6
  • 28
4
votes
1 answer

Max Prime Palindrome in Python

I'm trying to create a program that outputs the highest prime number than is a palindrome and is less than 1000. Expected output should be 929 Attempt 1 number = 1 prime = 1 maxNumber = 1000 while number > maxNumber: if str(number) ==…
Andy Wong
  • 341
  • 1
  • 2
  • 13
4
votes
1 answer

Reversing a string and palindrom time complexity in Python

Is the code below code good for checking whether a string is palindrome or not? What is its time complexity? I guess it's, O(1) am I right? Because we are just accessing the same string with different indexes and so accessing index O(1) is an…
4
votes
3 answers

Python Palindrome

So my task is to see and check a positive integer if its a palindrome. I've done everything correctly but need help on the final piece. And that the task of generating a new a palindrome from the one given given by the user. Am i on the right track…
Newb18
  • 167
  • 2
  • 11
4
votes
3 answers

Recursive method: why do I need return statement?

Just to practice recursion, I wrote one of the classic intro recursive functions - one that checks if a given string is a palindrome. My question is: within the first if statement, why do I have to write return palChecker(...) as opposed to just…
4
votes
3 answers

Creating an ArrayList based Stack and Using in Palindrome Detector

I need to create a myStack class and then use it to test for Palindromes... I chose to create an ArrayList based implementation of the stack. import java.util.ArrayList; public class myStack{ private ArrayList
4
votes
1 answer

What's Wrong With my Palindrome Program? (Ruby, user inputs the string themselves)

I so decided to make a palindrome program, but I did so by checking a string inputted by a user. In order to do this properly, I wanted to strip away the capitalization, spaces, and punctuation. I managed to get everything but the punctuation part…
4
votes
2 answers

How to generate a list of palindromes with only 'x','y' and a given length n in Python?

is there any patterns i can use to sort out how to create a string that is palindrome which made up with 'X' 'Y'
4
votes
2 answers

Number of distinct palindromic substrings

Given a string, I know how to find the number of palindromic substrings in linear time using Manacher's algorithm. But now I need to find the number of distinct/unique palindromic substrings. Now, this might lead to an O(n + n^2) algorithm - one 'n'…
Liam Willis
  • 661
  • 6
  • 17
4
votes
10 answers

Where's the bug in this function to check for palindrome?

Given below is the code to check if a list is a palindrome or not. It is giving correct output for 983. Where am I going wrong? def palindrome(num): flag=0 r=num[::-1] for i in range (0, len(num)-1): if(r[i]==num[i]): …
praxmon
  • 5,009
  • 22
  • 74
  • 121
4
votes
4 answers

Effective way of checking if a given string is palindrome in C

I was preparing for my interview and started working from simple C programming questions. One question I came across was to check if a given string is palindrome. I wrote a a code to find if the user given string is palindrome using Pointers. I'd…
Ani
  • 149
  • 1
  • 1
  • 8
4
votes
3 answers

How to calculate no. of palindroms in a large number interval?

I want to calculate how many numbers are palindrome in large interval data say 10^15 My simple code (python) snippet is: def count_palindromes(start, end): count = 0 for i in range(start, end + 1): if str(i) == str(i)[::-1]: …
CracLock
  • 653
  • 3
  • 9
  • 27
4
votes
6 answers

Recursive Function : Check for palindrome in Java

I have a class that checks whether a string is a palindrome or not. I have two questions. 1) Is this the most efficient way to check for palindrome? 2) Can this be implemented recursively? public class Words { public static boolean…
choloboy7
  • 287
  • 2
  • 7
  • 19
4
votes
2 answers

Comparing stack pop and queue dequeue in Java (palindromes)

Full disclosure: this is for an assignment, so please don't post actual code solutions! I have an assignment that requires me to take a string from the user and pass it into a stack and a queue, then use those two to compare the chars to determine…
idigyourpast
  • 714
  • 4
  • 12
  • 24
4
votes
6 answers

What possible improvements can be made to a palindrome program?

I am just learning programming in Python for fun. I was writing a palindrome program and I thought of how I can make further improvements to it. First thing that came to my mind is to prevent the program from having to go through the entire word…
jokerdino
  • 2,047
  • 1
  • 25
  • 31