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
-1
votes
1 answer

I am writing a code for palindrome for integer, Why are my strings not comparing to be equal even when they are the same

1.Palindrome code using strings #include using namespace std; int main() { int t,n; cin>>t; while(t--) { cin>>n; string num=to_string(n); string rev; //Reversed the string using for loop …
-1
votes
1 answer

How to reverse iterate a nested for loop in python?

There exists a string s = "abcd" How do I iterate through the string such that it produces the following output for its index: 3 32 321 3210 I have written the following code: for i in reversed(range(len(s))): for j in range(i, -1, -1): …
-1
votes
1 answer

longest palindromic substring solution

After completing the question on leetcode, I was reviewing other people's solutions and found that this had a crazy fast run time, but I don't fully understand the solution. Was hoping someone could explain it line by line, especially the elif…
isuf
  • 15
  • 4
-1
votes
2 answers

Check a String is Palindrome or not. C++

What is wrong in this? #include using namespace std; bool isPalindrome(string str) { char temp[1000]; int len=str.length(); int i=0; while(len) { len--; temp[i++]=str[len]; } temp[i]='\0'; if…
SKD
  • 1
  • 2
-1
votes
2 answers

Integer palindrome

x = int(input()) if x<0 and (x%10 == 0 and x !=0): print("false") rev = 0 while x>0: rev = rev*10 + x%10 x = x // 10 if rev == x: print("true") else: print("false") Since the reversed number is the same as entered one, the…
-1
votes
1 answer

How do I handle Palindrome with spaces in python?

I'm trying to check if a string is palindrome in python using deque. But the code below just checks a string with no space, how can I adjust it to a code which handles strings with spaces as well? e.g: It only works if I write the input as …
Shun
  • 21
  • 5
-1
votes
1 answer

I was trying to solve a Leetcode problem, regarding identifying if the number entered is a palindrome or not

I understood the logic behind the problem's solution, but in the coded solution I am a bit confused about the return statement in the end. Please explain to me what is its significance, why is it being used, etc ? (not why return is used but why is…
Zenraven
  • 3
  • 2
-1
votes
4 answers

"It's a Palindrome!" or "It's not a Palindrome!" are not printing when the string has spaces. How do I properly account for the spaces in a string?

Create a program, palindrome.py, that has a function that takes in one string argument and prints a sentence indicating if the text is a palindrome. The function should consider only the alphanumeric characters in the string, and not depend on…
user18493255
-1
votes
3 answers

return statement in Java use

I'm a beginner Java programmer. I am learning methods, functions and return statements. While solving questions on finding the prime numbers and palindrome numbers within a range given by the user I could notice that in the public static boolean…
-1
votes
2 answers

Python: Checking if a word has more than 3 of the same letters and returning false

I'm tasked with making a program that finds the longest palindrome in a given text that doesn't contain more than 3 of the same letters. #This program needs to find the longest palindrome # that does not contain the same letter more than 3…
-1
votes
1 answer

How to check whether a string array is a palindrome?

I've come across a problem where a string array value such as ["cat", "dog", "cat"] is considered as a palindrome, and something like ["dog", "dog", "cat"] is not. How would I go about checking an array like such to return true if it is indeed a…
Nahom H
  • 1
  • 1
-1
votes
2 answers

How to check for palindrome, ignoring special characters and case?

I have a palindrome: 'Mr. Owl ate my metal worm' Below is my code giving me output as False. def is_palindrome(value): lower = value.lower() return value == value[::-1] print(is_palindrome(input('Enter the value: '))) How can I improve my…
Karyala
  • 13
  • 6
-1
votes
1 answer

How do you create a palindrome generator as a recursive function?

Inverting a string is easy: def invert(text): if text == "": return text else: return invert(text[1:]) + text[0] I'm trying to create a recursive function that also keeps the original string, i.e.: 1234 -> 1234 4321 and 123…
student
  • 177
  • 2
  • 10
-1
votes
2 answers

Find minimum length of substring to rearrange for palindromic string

There is a string s. What is minimum length of substring to rearrange for making string s palindrome. Example: Input: abbaabbca Output: 4 I can rearrange substring from index 4 to 7 (abbc), and get abbacabba It is guaranteed that there is palindrome…
venom
  • 11
  • 2
-1
votes
1 answer

codewars Longest Palindrome kata: function returns -Infinity error

Task: https://www.codewars.com/kata/54bb6f887e5a80180900046b/train/javascript My solution: function longestPalindrome(str){ var Palindromes = [], reverser = i => i.split("").reverse().join(""), l = str.length; if (str === Infinity || str ===…