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
10
votes
4answers
8k views

Project Euler #4 - Largest Palindrome Product

Problem Statement: 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 ...
4
votes
3answers
2k views

Palindrome test

This is some code that determines if a string of characters is a palindrome or not. My professor says that there is a performance issue with the program, but I can't quite put my finger on it. Can ...
3
votes
3answers
417 views

Check if a string is palindrome or two strings are the opposite of each other

I made a function which checks if a word is the opposite of each other (ex: word and drow) and then realized that with minor changes it could also be used to detect if a word is palindrome. They both ...
3
votes
2answers
222 views

Calculate the largest palindromic number from the product of two 6-digit numbers (100000 to 999999)

Are there any efficient ways to solve this problem, for example using bitwise operator? ...
4
votes
2answers
3k views

Check if a string is a permutation of a palindrome using Python

This is a solution to exercise 1.4 from Cracking the Coding Interview written using Python 3. Given a string, write a function to check if it is a permutation of a palindrome. Example: 'Tact Coa' ...
4
votes
1answer
89 views

Return whether a string is a palindrome if you can delete at most k elements

The task: Given a string which we can delete at most k, return whether you can make a palindrome. For example, given 'waterrfetawx' and a k of 2, you could delete f and x to get '...
3
votes
1answer
261 views

Palindromic partitions solution

Task Find the smallest number of cuts required to break a string into a set of valid palindromes. For example: ababbbabbababa becomes a|babbbab|b|ababa (cuts = 3) partytrapb becomes partytrap|b (...
1
vote
2answers
46 views

Palindrome Pairs

The task is taken from leetcode Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] ...
2
votes
0answers
56 views

Longest Palindrome Substring: Where is the dynamic programming? [closed]

In this LeetCode problem, Longest Palindromic Substring, it is listed under Dynamic Programming for Google interview preparation. My understanding of dynamic programming is roughly "recursion + ...
4
votes
4answers
161 views

Largest Palindrome Product - Project Euler #4

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

Split string into as few substrings as possible such that each substring is a palindrome

The task Given a string, split it into as few strings as possible such that each string is a palindrome. For example, given the input string racecarannakayak, return ["racecar", "anna", "...
0
votes
1answer
59 views

Why does my function think that “uiouioiu”is a plaindrome? [closed]

I was reading Introduction to Computation and Programming using Python and there in an exercise, we had to write a function which would tell us if a given word is a palindrome or not, recursively. ...
4
votes
3answers
473 views

Determine whether an integer is a palindrome

The task Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: ...
4
votes
2answers
6k views

Check if string can be rearranged into a palindrome

I created a function to test whether a single word string can be a rearranged into a palindrome (doesn't have to be a real word). My logic was if the string has an even number of letters, then each ...
11
votes
5answers
815 views

Easy to read palindrome checker

I made a palindrome checker that's supposed to be designed to be simple and easy to read. Please let me know what you think. I believe the time complexity is \$\mathcal{O}(n)\$ but I'm not too sure ...
0
votes
0answers
153 views

Longest Palindromic Substring better approach

I have encountered to this question and applied a brute force algorithm off top of my head and couldn't find a better optimized solution. I was hoping I could get some insight to implement a better ...
5
votes
2answers
6k views

Finding the next palindrome of a number string

Here is the 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 ...
1
vote
1answer
62 views

Check if given integer is a palindrome

This code checks if the given integer is a palindrome. If it is, prints given integer is a palindrome else, not a palindrome: ...
1
vote
4answers
154 views

Read a palindrome of unknown length

I have a task to write the function: int read_palindrome(); // input comes from stdin which will read one line from standard input and returns 1 if the line is a ...
15
votes
5answers
5k views

Palindrome checking function

I recently did a little task for fun that required me to create a class to determine if a word is a palindrome or not. I know this is quite simple, but I'd be interested to know if a real developer (I'...
2
votes
1answer
87 views

Find palindromes in circular rotated string

I'm trying to tackle a programming challenge to determine how many palindromes exist in a given string that is being rotated character by character. My solution works, but it's too slow, and I'm ...
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 \$...
3
votes
4answers
2k views

Find longest Palindrome substring

I am preparing for technical interview and I found this question on geeksforgeeks, but I did not understand their solution. So, I have written my own solution. I want to optimize this code. ...
10
votes
2answers
202 views

Determining if a string can be permuted to a palindrome

I am going through Elements of Programming Interview by Aziz, Lee and Prakash one of the questions is how to determine if a string can be permuted to a palindrome. For example ...
2
votes
0answers
169 views

Longest Palindromic Substring challenge

My code is a mix-up between dynamic programming with the HashMap and brute force with the way I reach out the results and substring. I don't know how to optimize my ...
4
votes
2answers
73 views

Solve Project Euler #4 in PHP

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 the product of two 3-digit ...
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 <...
-2
votes
1answer
70 views

Find the first palindrome larger than the given number

Question Input number of test cases. Input each test case and output its next palindrome number. Link: https://www.spoj.com/problems/PALIN/ Language Used: C++14 (gcc 6.3) My code ...
1
vote
1answer
46 views

A program that checks for Palindromness

Yes, I made it up. This program checks if an entered string is a palindrome or not by assigning a char variable the characters ...
2
votes
2answers
105 views

Find a palindromic string in C

This program tests whether a string is a palindrome or not. Can there be any improvements or shortcuts that can be used in the program. You can give any type of string as input. The program finds does ...
8
votes
4answers
1k views

Test if a string is a palindrome

I got this out of an article on interviews / code challenges. The challenge text goes like this: A palindrome is a word, phrase, number, or other sequence of characters which reads the same ...
16
votes
3answers
13k views

Return the largest palindrome from the string

Here is the question: find the largest palindrome from a string. Ex: ABCBAHELLOHOWRACECARAREYOUILOVEUEVOLIIAMAIDOINGGOOD Result: ...
10
votes
5answers
433 views
7
votes
3answers
1k views

The Next Palindromic number

I have incremented an integer in the function nextpalin() and converted it into a std::string for finding whether it's a ...
0
votes
1answer
129 views

Find largest palindrome from the product of two 3-digit numbers

I think this is a good solution to finding the largest numeric palindrome that can be formed from the product of two 3-digit numbers... But it seems like there are some improvements that we could make ...
7
votes
1answer
2k views

Check if a given linked list is palindrome

I am solving interview questions from here. Problem :Given a singly linked list, determine if its a palindrome. Return 1 or 0 denoting if its a palindrome or not, respectively. Notes:Expected ...
4
votes
2answers
801 views

Next palindromic number

I wrote a function that takes a number and finds the next palindromic number. Time complexity is currently O(n2), which is really bad. How could one make this function more efficient? ...
0
votes
1answer
38 views
12
votes
4answers
9k views

Palindrome-testing Java program for an interview

In an interview I was asked to write a function that would take an input word and return true if the word is a palindrome. At first I used an approach using ...
2
votes
5answers
2k views

Determining if a palindrome exists in a linked list using recursion

Summary of code: This code recurses through half of the LinkedList, "adding" the left half node's to the call stack. Then, once at the middle, the code returns the ...
24
votes
5answers
1k views

Count distinct primes, discarding palindromes, in under 2 seconds

Problem Statement 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( ≤ 1015 ). Don't print more than 106 ...
1
vote
2answers
2k views

Count palindrome substrings

Given a string S, count and return the number of substrings of S that are palindromes. Single length substrings are also palindromes. We just have to count the substring that are palindrome. ...
0
votes
2answers
1k views

Palindrome algorithm

This code could be better? This is the algorithm: Compare the 1st character to the last character Compare the 2nd character to the second last character and so on Stop when the middle of the ...
4
votes
1answer
7k views

Create palindrome by rearranging letters of a word

Inspired by a recent question that caught my interest (now deleted), I wrote a function in Python 3 to rearrange the letters of a given string to create a (any!) palindrome: Count the occurrences of ...
2
votes
2answers
2k views

Largest palindrome made from the product of 3-digit numbers

I am given a task to write a program to find the largest palindrome made from the product of two 3-digit numbers. How can I improve this code? ...
4
votes
2answers
531 views

Finding palindromic strings of even length

Given a string of digits. Find the length of longest substring of even length i.e. 0,2,... which is a palindrome or which can be rearranged to form a palindrome (see example below). Here is my code: ...
6
votes
2answers
1k views

Counting the number of continuous palindromic substrings

Given a string of lowercase ASCII characters, find all distinct continuous palindromic sub-strings of it. Here is my code: ...
4
votes
1answer
571 views

C++ check if Palindrome

Just did this simple application to check whether a string is a palindrome or not ...
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 ...
1
vote
0answers
424 views

Python palindrome function; is it possible to write it without using string conversion?

I hope this question is okay to ask on Code Review; this is a little function I wrote in Python 2.7.12 that checks if a number is a palindrome. It works fine but I'd like to know if there is a purely ...