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
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 ...
2
votes
1answer
185 views

Implement a function to check if a linked list is a palindrome in c++

This is working example, I'm interested in mostly in knowing if there is any c++ related improvements you guys suggest? Also, do you think its better to solve this question iteratively or interviewer ...
3
votes
1answer
88 views

Checking for a palindrome in any sub-range of a range

This is my attempt at answering "Palindrome from all the substrings" which asks to detect if a string contains a palindrome as a substring. The algorithm implemented here is the one described in its ...
3
votes
1answer
387 views

Palindrome from all the substrings

This Problem is from https://www.codechef.com/problems/PRINCESS . The Problem in brief - i am given a string of length N. I have to check among all the the substrings that whether a substring exist ...
0
votes
1answer
172 views

Checking if a number is palindrome or not in Java

Got this question in a technical interview and here is my solution: ...
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 ...
1
vote
3answers
380 views

Checking if a string is a palindrome

This is the code for checking if a string is a palindrome. The execution time, for sample cases, is 0.40358 seconds. What must be done to increase the performance? ...
2
votes
1answer
157 views

Palindromic game in Python

This is just a little palindromic game that searches all palindromic numbers in ur random generated list. Feel free to give me some advice. ...
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 ...
6
votes
2answers
1k views

Length of longest palindrome subsequence

I had an interview, where I was asked to solve to this question: Given an string str, find the maximum length of palindrome subsequence. Example: >if str = 'abcda': maximum_length = 3 '...
26
votes
6answers
6k views

Close to the metal C++ Palindrome Program

I am attempting to reinvent the wheel by writing my own palindrome checking program in C++, using only basic loops and mathematical operations. I have arrived at a solution, but was wondering if it's ...
17
votes
8answers
4k 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 ...
3
votes
1answer
43 views

Complexity for two approaches of finding next biggest palindrome of a number

I have come up with a problem online about the next biggest palindrome of a number and i have solved the problem by two different approaches in python. The first one is, ...
2
votes
2answers
4k views

Finding the longest palindromic substring

I have the following code that works correctly. I am wondering if there is a simpler way to go about implementing my solution and/or if there is anything that looks non-standard in my code. If anyone ...
5
votes
2answers
594 views

Finding palindromes and reverse strings in C

I've created a program that will find if a word is a palindrome or a reverse string (emordnilap). How it works: The palindrome part works by reversing the string,...
4
votes
1answer
623 views

Find all sub matrices of type N*M in it which are palindromic

Today I had an interview, where I was asked to solve this question. A \$N*M\$ matrix is called a palindromic matrix, if for all of its rows and columns, elements read from left to right in a row are ...
3
votes
1answer
328 views

SPOJ: smallest palindrome larger than a given number

I am working on the SPOJ palindrome question. I'm using JAVA to solve it. The problem: A positive integer is called a palindrome if its representation in the decimal system is the same when read ...
7
votes
3answers
1k views

Leetcode 125. Valid Palindrome (better performance?)

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 ...
4
votes
1answer
381 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 ...
3
votes
1answer
244 views

Parallel brute-force solution for Project Euler 4 (Largest palindrome product)

The pe4Concurrent.go file given below is my first attempt at writing a concurrent programme, pe4.go is a non-concurrent implementation of the same algorithm for comparison purposes. The algorithm ...
5
votes
2answers
1k views

Valid palindrome solution

I'm working on this valid palindrome problem. Any advice on code bug, better idea for low algorithm execution time complexity, code style, etc. are highly appreciated. Problem Given a string, ...
2
votes
2answers
462 views

Check if a linked list is a palindrome in Scala

The problem: Palindrome: Implement a function to check if a linked list is a palindrome If it's a palindrome, the list must be the same backwards and forwards Below is the code I wrote: ...
2
votes
1answer
5k views

Get all possible palindromes in C#

As the title says, the goal is to get all the possible palindromes of a string in C#: ...
2
votes
3answers
904 views

Palindrome algorithm in C#

I had an interview yesterday where I had to write an algorithm on the whiteboard for working out if a value is a Palindrome in C#. The pressure got to me a bit but I've written my version of it in ...
4
votes
4answers
476 views

Check for Palindrome string in Java

I was wondering if you can give me advice on this solution to assess if an user input string is a palindrome or not. How can I optimize this solution? ...
1
vote
1answer
408 views

Checking if a number is a palindrome and is incrementing

Edit: Ok, this was a disaster of a question. I'll make sure to use timeit in the future I solved a Codewars problem that had the user check if a number was a ...
7
votes
4answers
6k views

Calculate the number of palindrome numbers in the given ranges

I've written a program that calculates all of the palindrome numbers in the given range, but the code is slightly slower than needed. I've tried to improve algorithmic complexity to the best of my ...
3
votes
2answers
396 views

Outputs all substrings that are palindromes in a given string, in alphabetical order without repitition

I'm currently trying to find a way to get my program to run more efficiently. If anyone has any ideas on how to optimize my program, i would appreciate it a lot. Also, the output has to display in ...
1
vote
1answer
405 views

Project Euler #4 - Largest Palindrome Project - Python

I solved the HackerRank version of the Largest palindrome problem (similar to Project Euler 4) in Python: Find the largest palindrome made from the product of two 3-digit numbers which is less than ...
7
votes
6answers
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 ...
10
votes
2answers
927 views

Check if a string is a permutation of a palindrome

I see a couple of these on codereview but I was hoping my way hasn't yet been encountered: ...
1
vote
1answer
971 views

Check string is permutation of palindrome

I assume there can be space in between and I have ignored that. Also, there will be only lower case characters in the string. My logic: There can be only one occurrence of odd number of character ...
1
vote
2answers
1k views

Finding the longest palindrome from the given string

Recently I came across this problem which instructs me to find the longest substring which is a palindrome: As we all know, a palindrome is a word that equals its reverse. Here are some examples ...
4
votes
2answers
507 views

Number of possible palindrome sequences

Here is the problem description from hackerearth.com: Rohan loves Palindromes. Palindrome is a string that read same forward and backward. For example abba is ...
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' ...
2
votes
1answer
442 views

Project Euler #4 - finding the largest palindrome from the product of two n-digit numbers

Project Euler Problem #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 ...
6
votes
1answer
88 views

PE4: Largest Palindrome Product (Clojure)

I solved Project Euler 4 using Clojure Lisp. 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 ...
2
votes
2answers
1k views

Simple Input Text Analysis

I've started learning java. I've written a small program I've done in C before. It's simple input analysis. If there is number, program checks if number is prime. Then write number: (value of input ...
5
votes
1answer
960 views

The Palindromic Odometer Puzzler: A Programmatic Solution

That is a programmatic solution to a puzzler from Car Talk, its summary is: "I noticed that the last 4 digits were palindromic. I drove a mile, and the last 5 were palindromic. I drove another ...
9
votes
1answer
493 views

Palindrome-inize a number

For example if I start with the number 146. I first reverse it, so it becomes 641. Then I add this to the original number to ...
5
votes
4answers
366 views

Ruby solution to Project Euler Problem #4: Largest palindrome product

I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it). ...
1
vote
0answers
121 views

Longest palindrome O(n^2)

After getting comments on my previous implementation, I have tried to implement with DP. But without using matrix. I am not doing any boundary checks on the string just wanted to see if I am missing ...
3
votes
2answers
258 views

Largest palindrome in the string

There are a lot similar questions out there. However, I wanted to get comments on my code. My implementation (as I believe) is simpler than the other complex ones as mine is \$O(n^2)\$. My approach ...
3
votes
2answers
2k views

Finding the index of the character whose removal will make a palindrome

Before I get into describing by problem I'd like to point out I found this question under c++ tag. But the solution of that question is already implemented in my ...
6
votes
2answers
126 views

Finding product palindromes

I am new to perl and want some help in tuning this script if possible cause it takes time if I increased my array. also if I use warnings I get a lot of warnings ...
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 ...
8
votes
3answers
634 views

Project Euler 4: Largest palindrome product

This solves Project Euler 4: Largest palindrome product using C# (specifically, using LINQPad). Any and all suggestions for improvements to either the C# code or the math/algorithm are very welcome. ...
6
votes
2answers
283 views

Longest palindrome in an array

I am new to programming, and think this code could be improved upon. Any suggestions? ...
2
votes
1answer
894 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 ...
4
votes
1answer
392 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 ...