Questions tagged [palindrome]

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

223 questions
Filter by
Sorted by
Tagged with
361 views

Longest palindrome in an array

I am new to programming, and think this code could be improved upon. Any suggestions? ...
946 views

Hackerrank Funny String python solution

"Funny String" problem from Hackerrank Suppose you have a String, $S$ of length $N$ indexed from $0$ to $N-1$. You also have some String, $R$, that is the reverse of $S$, where $S$ is ...
412 views

Improving time complexity of finding the longest palindrome in Python

The Longest Palindromic Substring challenge from InterviewBit: Given a string S, find the longest palindromic substring in S. where a "substring" must be contiguous, and in case of ties the first ...
545 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 ...
296 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: ...
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: ...
389 views

...
522 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 ...
298 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 ...
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: ...
806 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: ...
358 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. ...
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. ...
2k views

Check for palindrome in singly linked list

Looking for code review, optimizations and best practices. Node.java ...
260 views

...
810 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 ...
913 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. ...
221 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 ...
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 ...
198 views

Longest palindromes

I've been tasked to solve this exercise lately, and this is what I wrote: ...
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 ...
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? ...
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: ...
247 views

Determining if a sequence is a palindrome

To complement this Java question on palindrome identification, I came up with this C++(14) version: ...
467 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 ...
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) ...
134 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? ...
535 views

Integer Palindrome Check in C

This method should check whether a number is a palindrome or not: ...
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?)...
337 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 ...
16k 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 \\$...
1k views

Longest palindromic subsequence by memoization

I've written some code to solve the longest palindromic subsequence problem. ...
285 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. ...
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 ...
338 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 ...
183 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 ...
276 views

Palindrome Validator

This code returns true if the sentence is a palindrome, and false otherwise. Is there a better way of doing this? ...
742 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 ...
1k 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 ...
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. ...
610 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, ...
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 (...
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 ...
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: ...
475 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. ...
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 ...
177 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 ...
1k views

HackerRank challenge - index palindrome

I have a solution but it fails the performance for two tests. How can I speed it up? ...