Questions tagged [palindrome]

Any sequence of units (typically letters or numbers) that are read the same way forward or backward.

Filter by
Sorted by
Tagged with
5
votes
2answers
519 views

Palindrome evaluator in C++

I started learning C++ a few days ago, and this is my first full program. It takes in words until an end-of-file character prompt is given, and then outputs which of those words are palindromes and ...
1
vote
0answers
294 views

Longest palindrome subsequence

This algorithm finds the longest palindrome that is a subsequence of a given input string in \$\Theta(n^2)\$. Example Input: character Output: ...
3
votes
1answer
2k views

Faster palindrome checker in Java

I wonder if there could be a faster palindrome checker in Java. The best one I have is O(n/2) which is O(n) eventually: ...
2
votes
0answers
383 views
6
votes
1answer
505 views

Palindromes that are sum of consecutive squares

I have been working on a Project Euler: 125, which took me ages to solve. The problem and source are cited below The palindromic number 595 is interesting because it can be written as the sum of ...
3
votes
2answers
281 views

Largest palindrome product

From the Project Euler challenge series: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest ...
1
vote
1answer
2k views

Rearrange characters of a string into a palindrome, if possible

I have written Python code which works absolutely fine but I am looking for other ways to do this: ...
1
vote
2answers
758 views

Finding palindromes and the longest word in a string

I have two little projects that I've been working on. One is to find all palindromes: ...
3
votes
1answer
343 views

Determining if a string is a palindrome of a permutation

I wrote code to determine if a string is a palindrome of a permutation. This exercise was taken from Cracking the Coding Interview. I'm looking for any tips on improving it. ...
-1
votes
1answer
2k views

Determining whether a string can be rearranged into a palindrome

For a string, count the number of occurences of each character. If at most one character has odd count then the string can be a palindrome else it's not. ...
4
votes
3answers
2k views

Check for palindrome in singly linked list

Looking for code review, optimizations and best practices. Node.java ...
3
votes
1answer
241 views
3
votes
2answers
798 views

Checking if a single linked list is a palindrome in C++

The following is my first try at this classical interview question. It is quiet different from the solutions Gayle Laakmann provides in her book, and in another question on stackoverflow, someone ...
3
votes
5answers
890 views

Python palindrome checker

This is my palindrome-checker that is doing what it should do. If you have any additional suggestions, please let me know. ...
2
votes
1answer
212 views

196-Algorithm Program

Attempting to see whether using 196 as a respectively in my program will have a result or not, I made a simple function to test it. Now the 196-Algorithm requires ...
2
votes
3answers
4k views

Reverse digits and add until a palindrome appears

The following code is a C solution to the following problem UVA 10018. The Problem The "reverse and add" method is simple: choose a number, reverse its digits and add it to the original. If ...
2
votes
2answers
197 views

Longest palindromes

I've been tasked to solve this exercise lately, and this is what I wrote: ...
3
votes
4answers
5k views

Find a palindrome using Ruby

I am preparing for an upcoming exam and have the following practice question.. Write a method to determine if a word is a palindrome, without using the reverse method. Most of you probably know ...
8
votes
4answers
3k views

Program to Check If string is Palindrome (in C) [closed]

Just wrote a program to check if a string is Palindrome. If that's true, return 1. Else, return 0. How can I improve it? ...
2
votes
0answers
62 views

Determining if a genetic sequence is palindromic

Adding another level to my previous question on 'normal' palindrome identification, in this one I'm interested in identifying genetic palindromes. Here's my attempt: ...
4
votes
1answer
232 views

Determining if a sequence is a palindrome

To complement this Java question on palindrome identification, I came up with this C++(14) version: ...
6
votes
3answers
452 views

Project Euler #4 in C++: largest palindrome product of two 3-digit numbers

Project Euler #4 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from ...
1
vote
2answers
1k views

Check if a linked list is a palindrome in O(n) time and O(1) space

I liked this problem because there are so many sub-problems that are interview problems in their own right-- (reverse linked list, find midpoint) ...
4
votes
1answer
132 views

Worst case runtime analysis of a string partitioning algorithm

Give all the partitionings of a string s such that every substring of the partition is a palindrome What is the time complexity of this solution? And, how can I improve my code overall? ...
3
votes
3answers
529 views

Integer Palindrome Check in C

This method should check whether a number is a palindrome or not: ...
20
votes
10answers
5k views

Palindromes in C

The function tests whether or not the provided string is a palindrome, and the main function just times how quick it is (after all, C's supposed to be quick, right?)...
6
votes
1answer
320 views

Next Palindrome

I've written a function which, given a number string, returns the next largest palindrome in string form. For example, if the input string is "4738", the output ...
6
votes
2answers
14k views

Find all distinct palindromic sub-strings for a given string

I was solving a question where I had to find all possible unique palindromes of size greater than 1 for a string. I was able to come up with the solution shown below. If I am not mistaken it is an \$...
6
votes
1answer
1k views

Longest palindromic subsequence by memoization

I've written some code to solve the longest palindromic subsequence problem. ...
2
votes
3answers
261 views

Palindrome numbers - Project Euler Problem 4

Project Euler Problem #4: Largest palindrome product: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. ...
4
votes
2answers
2k views

Find palindrome in a string

The purpose of this code is to find the largest palindrome in a string. It works fine when the string is short, but every time I test this code with 1000+ characters in a string, it takes forever to ...
4
votes
1answer
315 views

Finding palindromes in C#

This is my first foray into OOP, so I'd appreciate any kind of advice! Here is the problem description: On the first line of the input, you will receive a number specifying how many lines of ...
4
votes
2answers
174 views

Palin Pairs (Pallindrome Counting) Code

In an array of strings 'a' having 'n' strings i have to select the Palin Pairs from the given strings .for ex for input 3 bba abb abb Output=2 I am getting correct output but want to reduce time ...
3
votes
3answers
265 views

Palindrome Validator

This code returns true if the sentence is a palindrome, and false otherwise. Is there a better way of doing this? ...
7
votes
4answers
735 views

Largest palindrome that can be made from a product of 2 3-digit numbers (Project Euler 4)

This is my solution to Project Euler #4, which asks for the largest palindrome that can be made from a product of 2 3-digit numbers. I have done a brute force method, but it takes around 10-20 seconds ...
2
votes
3answers
967 views

Removal of a character to make a string a palindrome

This code determines which index for a given string if that character is removed will produce a palindrome string. For eg s = "baa" After removing b the string "aa" is palindrome. Here ...
3
votes
3answers
3k views

Finding number of palindrome pairs in an array

I am trying to find the number of string pairs in an array that are palindromes. ...
3
votes
1answer
603 views

Project Euler 348: Sum of a square and a cube

Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way. Consider the palindromic numbers that can be expressed as the sum of a square and a cube, ...
8
votes
1answer
11k views

Finding all possible distinct palindromes of a string

There was some online test where I was asked about finding all possible distinct palindromes of a string. Here I had to give the count of all possible distinct palindromes of a given string (...
1
vote
2answers
1k views

Making numbers palindromic

This is a challenge I found here. You're suppose to list how many steps it takes to convert a number to a palindromic number, where each step consists of adding number to the reverse of itself. For ...
2
votes
1answer
2k views

Checking if any permutation of a string can make it palindrome

I was writing code to check if any permutation of a string can make it palindrome and came up with the following logic: ...
2
votes
3answers
464 views

HackersEarth - Reverse primes

Generate as many distinct primes P such that reverse (P) is also prime and is not equal to P. Output: Print per line one integer( ≤ 10^15 ). Don't print more than 10^6 integers in all. ...
12
votes
4answers
10k views

Palindrome Checker in Java

My objective is to take a string as input and determine if it is a palindrome. I'm wondering how I could improve this code (efficiency, bugs, etc). I'm relatively new to Java so I'm expecting that my ...
1
vote
2answers
176 views

Checking a numeric palindrome

Given A and B, count the numbers N such that A ≤ N ≤ B and N is a palindrome. Input: First line contains T, the number of testcases. Each testcase consists of two integers A and B in ...
4
votes
2answers
904 views

HackerRank challenge - index palindrome

I have a solution but it fails the performance for two tests. How can I speed it up? ...
8
votes
3answers
5k views

Project Euler #4 - Largest Palindrome Product in Java

I am seeing that this is actually not in accord with the difficulty level said there. Firstly I cannot list all possible improvements it could have. ...
3
votes
5answers
13k views

Check if a given string can be a palindrome by altering some character without using a library function

I was asked in an interview to write code to check if a given string is a palindrome or can be a palindrome by altering some character without using library function. My logic is to: Compare 1st <...
4
votes
2answers
291 views

Largest palindrome in a string

I am working on a question in which I need to find a largest palindrome given a string. Here is the description. ...
3
votes
6answers
6k views

Largest palindrome made from the product of two 3-digit numbers

I am working on an interview question in which I need to find the largest palindrome made from the product of two 3-digit numbers. Here is the question. ...
2
votes
1answer
99 views

Palidrome checker in haskell

I decided to avoid the trivial isPalindrome lst = lst == reverse lst and tried writing a method with pattern matching and recursion. ...