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
0
votes
2 answers

To check wether a given string seqence is palindrome or not using stacks

I want to know how to store the characters or integers popped from stack to be stored so that I can compare it with the original string or int value. For example : n = 1221; n = n / 1000; // so that i get the last digit in this case 1 and dividing…
john
  • 53
  • 1
  • 6
0
votes
1 answer

Palindrome program produces incorrect output

I'm trying a problem on SPOJ ("Sphere Online Judge", a programming puzzle site), where I need to generate the smallest palindrome larger than the given number. I tried to solve it by calculating two sides of palindrome with modulo and int division,…
bartexsz
  • 239
  • 1
  • 11
0
votes
3 answers

Testing palindrome with nested loops

I understand that this is the easiest and most simplest way to check: if val == val[::-1]: print "yes" else: print "no" but just for practice, I wanted to test it with nested for loops (using the reversed() function -- I spent hours but…
eozzy
  • 66,048
  • 104
  • 272
  • 428
0
votes
3 answers

Comparing strings excluding punctuation and whitespace

I'm making a program to find the larges palindrome in C++ and I need to get the palindromes for the inputted strings ignoring the case, punctuation and whitespace. For example, see the following line: Confusius say: Madam, I'm Adam. Here, the…
Roshnal
  • 1,284
  • 3
  • 16
  • 39
-1
votes
2 answers

Java decimal to binary without api's and strings

I must write a program in java (homework) that gives the input (x), the input in binary, tells if the input is a palindrome and tells if the binary from the input is a palindrome. I may not use api's other than System.out.print and I may not use…
Waarten
  • 115
  • 6
-1
votes
1 answer

Count palindrome number that have total digits is divisible by 10

How to count many palindrome number that have total digits is divisible by 10 from L to R (1 <= L <= R <= 10^12) in 0.5s? My idea: generate palindrome number then count. But it is TLE. Here is my code: def circle_num(x): t = 0 for digit in…
-1
votes
4 answers

Python - Leetcode 9. Palindrome Number - formatting my solution into the leetcode format

Beginner here. I did "Leetcode 9. Palindrone Number" and think I figured out the solution, but as a beginner I am not familiar with some basic Python formats. Leetcode Problem = Given an integer x, return true if x is a palindrome, and false…
-1
votes
2 answers

having problem on a code it took time more than it required ( O(n^2) ). how to reduce execution time

the function of code is to find a palindrome substring at any index. code is running well and having no errors but the main problem is that it took time more than it specified. i tried every possible action but couldn't get the desired execution…
-1
votes
2 answers

Largest Palindrome of two digit numbers

The program below is to find palindromes in products of 2 digit numbers (up to 10*11 for trails). #include using namespace std; int res1=0 void palindrome(int mul) { int k,res=0,count=0; int p=mul; while(mul!=0) { …
srija
  • 1
  • 1
-1
votes
2 answers

How do I write a Python code to check if the given sequence is a palindrome or not?

I wish to learn more about the rev_string I tried to see if "MOM" is a palindrome and I wanted the result to be yes/no
-1
votes
1 answer

Check if a numeric string is palindrome in Python

Below is my code: def check_palindrome(num): my_str = str(num) my_list1 = list(my_str) my_list2 = list(my_str) my_list2.reverse() if my_list1 == my_list2: return "It's palindrome" else: return "Not a…
-1
votes
2 answers

What's wrong with my code?Valid Palindrome 2- Leetcode 680

Given a string s, return true if the s can be palindrome after deleting at most one character from it. Example 1: Input: s = "aba" Output: true Example 2: Input: s = "abca" Output: true Explanation: You could delete the character 'c'. Example…
redox741
  • 21
  • 5
-1
votes
1 answer

An efficient function to check if a singly linked list is a palindrome or not in C

I came up with a solution that can check if a singly list is a palindrome or not. but the solution is not efficient enough. Please i need a suggestion, thanks in advance. Here is the code: int is_palindrome(listint_t **head) { listint_t…
-1
votes
2 answers

Break out of a while loop to find a Palindrome

This code does not work! It causes the browser to crash; Can someone please help me debug this? Not sure what is wrong. My assumption is I have a pointer at the beginning of the string and the end of the string, And I check if each character is the…
Antonio Pavicevac-Ortiz
  • 7,239
  • 17
  • 68
  • 141
-1
votes
1 answer

My palindrome code says that any string starting and ending with the same letter is a palindrome

I've been learning Java for about a week now and had a question about base cases in recursion in this palindrome code I'm writing. Essentially when the input is any string that has the same first and last letter, the program prints that it is a…