Skip to main content

Questions tagged [palindrome]

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

18 votes
8 answers
5k views

Project Euler Problem #4 - Palindromic number

The problem is as follows: 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 ...
IvenBach's user avatar
  • 3,487
13 votes
10 answers
8k views

Tests for palindromes in C and C++

A question I've been asked on interactive phone screens is to code a test to determine whether a string is a palindrome or not. I am providing two examples here: one in C and one in C++. They both ...
pacmaninbw's user avatar
  • 24k
4 votes
1 answer
579 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 ...
Mona Jalal's user avatar
30 votes
9 answers
58k views

Check a string to see if it is a palindrome

I have written two code pieces to check if a given string is a palindrome: ...
Rohit's user avatar
  • 1,066
25 votes
5 answers
2k 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 ...
Akash Rana's user avatar
21 votes
10 answers
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?)...
Sam McCreery's user avatar
17 votes
5 answers
25k views

Longest palindrome in a string

Please be brutal, and judge my code as if it was written at a top 3 tech company, straight out of college. (The method signature, and input parameter is given by the problem, so don't worry about that)...
bazang's user avatar
  • 2,236
17 votes
3 answers
18k views

Return the largest palindrome from the string

Here is the question: find the largest palindrome from a string. Ex: ABCBAHELLOHOWRACECARAREYOUILOVEUEVOLIIAMAIDOINGGOOD Result: ...
Love's user avatar
  • 369
10 votes
5 answers
2k 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 ...
481b8423202598ecfb233c5fa68caf's user avatar
10 votes
4 answers
2k views

Checking whether a string is a permutation of a palindrome in C++20

(See the next iteration/follow-up here.) I have this short function is_permutation_palindrome, which returns true only if the ...
coderodde's user avatar
  • 28.9k
7 votes
6 answers
2k views

Generalized Project Euler #4: Largest palindrome from product of two n-digit numbers in Python

This solves Project Euler 4: Largest palindrome product using Python (not limited to 3 digit numbers). I need suggestions for improvements to either the Python code or the math/algorithm since time of ...
Amey Dahale's user avatar
7 votes
5 answers
986 views

Checking whether a string is a permutation of a palindrome in C++20 - follow-up

This post is the follow-up of Checking whether a string is a permutation of a palindrome in C++20. So, what's new? Well, nothing else except that the procedure is now generic and accepts all ...
coderodde's user avatar
  • 28.9k
6 votes
2 answers
4k views

Finding the largest palindrome from the product of two n-digit numbers

The program finds the largest palindrome made from the product of two n-digit numbers, where n is specified by the user. The code included works, however, when the user enters 5 or greater, the ...
rrazd's user avatar
  • 173
4 votes
5 answers
17k views

Determining if a sentence is a palindrome

The biggest problem I see in checking palindromes on the Internet is when the user inputs a palindrome sentence or phrase and the program returns a wrong output. So for me, I tried to optimize ...
Yodism's user avatar
  • 751
4 votes
1 answer
598 views

Leetcode 125. Valid Palindrome

Problem statement Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a ...
Jianmin Chen's user avatar
  • 2,396

15 30 50 per page