FAQ Database Discussion Community

## Online judge Rejecting My Answer

c++,long-integer,palindrome
The Next Palindrome The below code is the solution to this problem A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than...

## longest palindromic substring recursive solution

c++,algorithm,recursion,dynamic-programming,palindrome
I am aware of solutions that uses the bottom up dynamic programing approach to solve this problem in O(n^2). I am specifically looking for a top down dp approach. Is it possible to achieve longest palindromic substring using a recursive solution? Here is what I have tried but it fails...

## Why is S == S[::-1] faster than looping?

python,string,performance,palindrome
Why is the pythonic way of checking if a string, S, is a palindrome -- S == S[::-1] -- faster than the following implementation? i = 0 j = len(S) - 1 while i < j: if S[i] != S[j]: return False i += 1 j -= 1 return True...

## My do/while loop messes my program up the second time around

java,java.util.scanner,do-while,palindrome
The issue I am having is once I input a word like "non" I get back it IS a palindrome. I then type "Yes" as I ask "Keep Going?". It starts back up at "Type Word:" and I type "non" again. This time however I get back it is NOT...

## How to check if a sequence could be turned into a palindrome

python,sorting,python-3.x,palindrome
I have to find if a list can be a palindrome. The first part of my program sorts the list. A = [0, 99, 97, 97, 99, 100, 100, 0] # sorted: B = [0, 0, 97, 97, 99, 99, 100, 100] This list can be a palindrome because it...

## Is there something different with C in Hackerrank(getting different output)?

c,printf,output,palindrome
I've been trying to do the Love-Letter Mystery Challenge on Hackerrank. Here are the rules: https://www.hackerrank.com/challenges/the-love-letter-mystery And here's my solution: #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define MAX 1000 int check_palindrome(char *A) { int i = 0, j; while(A[i]) i++; i -= 1; for(j = 0; j <=...

## find closest palindrome date of a given palindrome date [closed]

c,algorithm,palindrome
A palindrome date is given and we have to find the closest palindrome date of this given date. The result date should be before the given date. Date is in the format of YYYY/MM/DD. One brute force solution is (pseudo-code is given which might not be efficient). Convert the string...

## Palindrome checker - spacing

java,palindrome
I have a program where I am typing a Java program to check if the String entered is a palindrome. I have 2 problems going on that I can not for the life of me seem to figure out. I have typed out the code so that it will tell...

## I need an explanation for this palindrome [closed]

java,for-loop,palindrome
Can anyone explain me this palandrome from the "for loop" with an example? I do not understand how the for loop works, it would be a great deed if you guys help me understand. import java.util.*;` public class palindrome { public static void main(String args[]) { String original, reverse =...

## Can someone explain me how this code works? (Palindrome C++)

c++,palindrome
I have a working code but I don't quite understand how it works, I know it's meaning and use but I don't understand how it works. #include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { int n, num, digit, rev = 0; cout << "Enter a...

## Palindrome Test: Debugging

java,debugging,recursion,palindrome
I'm having trouble figuring out the bug(s) in my code. I know there is one except I'm not sure what it is. I am new to coding and this is only my second semester, my professor had us skip to the end of the book to learn recursion however in...

## My Java program is only outputting two answers, the other two aren't shown

java,for-loop,methods,palindrome,perfect-numbers
My program should spell the inputted word backwards, follow to the next line and answer if the word inputted is a Palindrome. Then it will take the accompanying number, output if it is prime or not then output if it is perfect or not. My output in command prompt is...

## Palindrome checker - What am i doing wrong?

java,swing,loops,palindrome
I am to create a program that checks for palindromes in a sentence and display the palindromes that have been found. My following code keeps giving me a "String is out of bounds" error. What am i doing wrong? My Program: import javax.swing.JOptionPane; public class Palindromechkr { public static void...

## Issue with Palindrome class using Stacks

java,stack,palindrome
I am trying to write a Palindrome class using Stacks to determine if a word entered by user is a palindrome. There seems to be an issue in my Palindrome class. Can someone please help me identify it? My program works but no matter what word I type, it returns...

## Constructing palindrome from a list of words

c++,algorithm,search,palindrome
Recently I was looking through some interview questions, and found some interesting one: You are given a list of word. Find if two words can be joined to-gather to form a palindrome. eg Consider a list {bat, tab, cat} Then bat and tab can be joined to gather to form...

## One of the solution for finding the longest palindromic substring could not be understood

algorithm,palindrome
Refer to this article on leetcode, there's a common mistake for solving the longest palindromic substring problem: Reverse S and become S’. Find the longest common substring between S and S’, which must also be the longest palindromic substring. For instance: S = “abacdfgdcaba”, S’ = “abacdgfdcaba”. The longest common...

## JAVA: Error reversing a string to check for palaindrome off-by-one i think

java,for-loop,palindrome,charat,off-by-one
I am having a problem. I received an assignment to write pseudo code for a palindrome checking program. My problem is that while I received good marks on my pseudocode assignment, when I tried to write the code in java for my own edification, I was unable to make one...

## How to detect palindrome cycle length in a string?

string,algorithm,palindrome
Suppose a string is like this "abaabaabaabaaba", the palindrome cycle here is 3, because you can find the string aba at every 3rd position and you can augment the palindrome by concatenating any number of "aba"s to the string. I think it's possible to detect this efficiently using Manacher's Algorithm...

## Palindrome Check in Java using two Methods will not compile [closed]

java,methods,compilation,palindrome
I was working on this for a class assignment, and I cannot for the life of me get it to compile. I keep getting this error: CPT236PalindromeCheckMethod.java:52: error: reached end of file while parsing } ^ 1 error I have tried adding, removing, and checking all of my braces, but...

## Java: Figuring out if a phone number (string) is a palindrome

java,palindrome
I need to find out if a phone number is a palindrome. I have this code: public static boolean isPalindrome(String j) { boolean pali; String rev = ""; String reverse = new StringBuffer(j).reverse().toString(); j.toString(); if (j.equals(reverse)) pali = false; else if (!j.equals(reverse)) pali = true; return pali; } This code...

## Forming Palindrome from a String

java,string,algorithm,palindrome
I was solving Longest Palindrome in a String problem, where we are searching for the longest substring forming a palindrome. My code for the above is : private static int palindrome(char[] ch, int i, int j) { // TODO Auto-generated method stub if (i == j) return 1; // Base...

## Python palindrome program not working

python,recursion,palindrome
I've written a simple program in python which checks if the sentence is palindrome. But I can't figure out why isn't it working. The results is always False. Does anyone knows what's wrong? def isPalindrome(word): # Removes all spaces, and lowercase the word. word = word.strip().lower() word = word.replace(" ",...

## Given length L find the shortest string formed only of as & bs >= L such that adding some character (Either a or b) doesn't produce a new palindrome

string,algorithm,palindrome
Given length L find the shortest string >= L formed only of as & bs such that adding some character (Either a or b) doesn't produce a new palindrome substring (never seen before palindrome) For example for L = 1 there is the string aabbaba, adding "a" to it to...

## Comparison of Fixnum with nil failed - palindrome program Ruby

arrays,ruby,null,palindrome,fixnum
I was working on a program for question 4 in Project Euler - find the largest palindrome among multiples of 3-digit numbers. This is what I wrote: def palintest(number) num = number.to_s len = num.length if len % 2 != 0 num[(len/2).floor] = '' end if num[0.. (len/2)-1] == num...

## Proving that a reversible list is a palindrome in Coq without exists tactic

exists,palindrome,coq
For an exercise in software foundation I want to prove the following theorem : Theorem rev_pal {X:Type} : forall (l:list X), l = rev l -> pal l. pal is defined as follow : Inductive pal {X:Type} : list X -> Prop := | pal_nil : pal [] | pal_one...

## remove both commas and white space ruby

ruby,regex,string,palindrome
I am new to ruby and my regex knowledge leaves a lot to be desired. I am trying to check if a string is a palindrome, but wish to ignore white space and commas. The current code I have is def palindrome string string = string.downcase string = string.gsub(/\d+(,)\d+//\s/ ,"")...

## I need an explanation on slice()

javascript,function,slice,palindrome
I was completing javascript exercises and got stuck on creating a function which checks if a string is a palindrome. For your reference, this was the given solution. I understand what slice() does as a method, and I followed the function here until the point where it checks to see...