Questions tagged [palindrome]

A word, phrase, number, or other sequence of units that may be read the same way in either direction, forward or backward.

A word, phrase, number, or other sequence of units that may be read the same way in either direction, forward or backward.

Spacing and punctuation is generally ignored when attempting to determine whether the potential palindrome under consideration is in fact a palindrome. One such example is:

I, madam, I, made radio - so I dared! Am I mad? Am I?

(from http://www.joe-ks.com/palindromes.htm)

1763 questions
9
votes
8 answers

How to detect the first occurrence of palindrome

Suppose you are reading from a character stream, the function should return when you have read the first occurrence of palindrome. The length of the palindrome should be even number. The requirement of the time complexity is O(N). Example: 1st…
Kan
  • 113
  • 5
8
votes
18 answers

How to check if the binary representation of an integer is a palindrome?

How to check if the binary representation of an integer is a palindrome?
yesraaj
  • 46,370
  • 69
  • 194
  • 251
8
votes
3 answers

How do I efficiently determine the longest individual character palindrome in a given string?

Given a string of length N containing characters [A-Z], how do I determine the longest palindrome for an individual character? I will illustrate this with an example: Given string: JOHNOLSON In analyzing the string, we find that we have a palindrome…
jbranchaud
  • 5,909
  • 9
  • 45
  • 70
8
votes
7 answers

Reverse digits in R

How can you reverse a string of numbers in R? for instance, I have a vector of about 1000 six digit numbers, and I would like to know if they are palindromes. I would like to create a second set which is the exact reverse, so I could do a matchup.
Thomas
  • 847
  • 4
  • 12
  • 21
8
votes
24 answers

Check if a permutation of a string can become a palindrome

Write a method to test if a string meets the preconditions to become a palindrome. Eg: Input | Output mmo | True yakak | True travel | False I'm thinking of this approach: Make a suffix tree for all permutation of T such that…
user5080124
8
votes
4 answers

One of the solution for finding the longest palindromic substring could not be understood

Refer to this article on leetcode, there's a common mistake for solving the longest palindromic substring problem: Reverse S and become S’. Find the longest common substring between S and S’, which must also be the longest palindromic…
Judking
  • 6,111
  • 11
  • 55
  • 84
8
votes
2 answers

What's the time complexity of this algorithm for Palindrome Partitioning?

Palindrome Partitioning Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Personally I think, the time complexity is O(n^n), n is the length of the given…
Zhaonan
  • 939
  • 1
  • 11
  • 20
8
votes
6 answers

Closest Palindrome Number

I came across one of the common interview question which was to find the closest palindrome number. Say if the input is 127 then output will be 131 and if it is 125 then it should give 121 as output. I can come up with the logic but my logic fails…
Naveen
  • 139
  • 2
  • 11
8
votes
11 answers

Add the least amount of characters to make a palindrome

The question: Given any string, add the least amount of characters possible to make it a palindrome in linear time. I'm only able to come up with a O(N2) solution. Can someone help me with an O(N) solution?
Waley Chen
  • 929
  • 3
  • 10
  • 23
8
votes
14 answers

highest palindrome with 3 digit numbers in python

In problem 4 from http://projecteuler.net/ it says: 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…
FabianCook
  • 20,269
  • 16
  • 67
  • 115
8
votes
5 answers

Efficient way to verify if a string is a rotated palindrome?

A rotated palindrome is like "1234321", "3432112". The naive method will be cut the string into different pieces and concate them back and see if the string is a palindrome. That would take O(n^2) since there are n cuts and for each cut we need O(n)…
Wei
  • 422
  • 1
  • 7
  • 15
7
votes
2 answers

How does recursive isPalindrome function work?

I'm working on some introductory recursion problems and I have a clarifying question I'd like to get answered. The most nagging question I have is how is this recursion operating in the solved problem below? Despite having solved the problem, I'm…
gryb
  • 115
  • 2
  • 3
  • 6
7
votes
3 answers

Fastest algorithm to find the largest palindrome that is the product of 2 numbers with the same number of digits

How do I make this code run in under 30s to find the largest palindrome that is the product of 2 numbers with the same number of digits? def palindrome(maxInt): pa=[] for x in range(maxInt,0,-1): for y in range(maxInt,0,-1): …
YEp d
  • 154
  • 1
  • 9
7
votes
6 answers

Palindrome Using a stack

Our professor required us to check if a word is a palindrome by using stacks. Every time I run it, there's an error: Unhandled Exception. Access violation What am I doing wrong? How can i improve my code? My code is as follows: typedef struct…
newbie
  • 14,582
  • 31
  • 104
  • 146
7
votes
1 answer

Palindrome Permutation (Cracking the Coding Interview 1.4)

I'm having trouble understanding the bit logic in these two functions. I don't know why we are checking for the condition (bitVector & mask) == 0. Also, why do we OR the bitVector with the mask when the condition is satisfied and AND the bitVector…
Decimal
  • 103
  • 1
  • 8