Questions tagged [palindrome]
Any sequence of units (typically letters or numbers) that are read the same way forward or backward.
236
questions
0
votes
1answer
70 views
Algorithm For Longest Palindrome
I made an brute force algorithm to find the longest palindrome within the string. This palindrome is a substring of the input. Below is the code.
...
4
votes
1answer
83 views
Check if string is palindrome LeetCode
LeetCode 125 requires receiving a string and checking if it is a valid palindrome. I have done this and am confident with an int and a single word, but this question requires the use a of a sentence ...
3
votes
1answer
88 views
palindrome code in C times out in program challenge?
Hello I am making a code in C to find the value of the last sequence of palindromes of a specified size (d) and I need to optimize this code as it is for an ...
9
votes
1answer
229 views
LeetCode on Longest Palindromic Substring in Python
This is a programming question from LeetCode:
Given a string s, return the longest palindromic substring in s.
Example 1:
Input: s = "babad" Output: "bab" Note: "aba" is ...
4
votes
4answers
947 views
Check if a binary tree is symmetric in Python
I have solved the following Leetcode problem.
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric....
3
votes
2answers
122 views
Palindrome Algorithm and JUnit 5 Tests
I have a "Palindrome" class that has some functions for verifying if certain things are Palindromes. For the verification, I have 2 different algorithms, one being recursive and the other ...
2
votes
4answers
678 views
Python palindrome checker function
For practice purposes I implemented a function that checks for palindromes:
...
3
votes
1answer
65 views
Optimizing code solution for Palindrome Index-Hackerrank
I submitted my solution for palindrome Index coding challenge but I get "test cases terminated due to time out error". My code is working and so I don't know what else to do to optimize it. Please ...
2
votes
0answers
51 views
HackerRank's Challenging Palindromes solution times out for certain tests
I am trying to solve the Challenging Palindromes problem from HackerRank. The code that I have got so far fails only for large inputs due to timeout, every other test it passes successfully.
The ...
4
votes
1answer
48 views
A fast generator of palindrome dates in chronological order
02/02/2020 is a palindrome day because reading the date left-to-right or right-to-left still refers to the same calendar date. And because it doesn't
matter whether you use the DD/MM/YYYY format or ...
9
votes
5answers
3k views
Palindrome checker program
I've been studying Java for some days and I'm just now starting to make some simple programs, I'd like to know if there's any 'noob' mistakes or habits that I could avoid.
In other words: how could ...
7
votes
2answers
1k views
Python palindrome program
I have written a palindrome program. And I was just wondering if it correct? I checked using the words racecar and madam, and it says they are palindromes. I have also tested nonpalindrome words and ...
1
vote
0answers
50 views
How do I optimize memoization in order to find longest palindromic substring?
I want to find the longest palindromic substring using dynamic programming in Python3. The strings can be as large as this string.
I have seen other questions on this problem that successfully solve ...
3
votes
0answers
85 views
Longest palindrome code in C# takes time out on LeetCode
I like to request a review of the code below, which is my attempt at answering the question here on LeetCode site. The code passes 43 tests, but it times out on the next one. I copied and ran the test ...
0
votes
3answers
77 views
Basic Palindrome check comparing chars
I've seen variations of this assignment where you reverse a string to match it to the original to find out if it is a palindrome, but this version I made only iterates through half of the string ...
6
votes
3answers
686 views
CTCI Chapter 1 : Palindrome Permutation
Below is my code for the problem 1.4 in CTCI. I would like a review of my code and if my approach to the problem is correct.
Problem Statement:
Palindrome Permutation: Given a string, write a ...
3
votes
1answer
104 views
Project Euler - Problem No.4 - Largest palindrome product
according to the problem:
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 ...
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
2answers
350 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?
...
3
votes
1answer
319 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
91 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] ...
3
votes
0answers
209 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
194 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.
Find ...
0
votes
1answer
64 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.
...
6
votes
3answers
2k 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:
...
5
votes
1answer
152 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 '...
11
votes
5answers
885 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 ...
4
votes
2answers
456 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 ...
1
vote
1answer
89 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
230 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 ...
2
votes
1answer
197 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 ...
10
votes
2answers
212 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
184 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
81 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
4answers
3k 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.
...
-2
votes
1answer
84 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
48 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
243 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 ...
10
votes
5answers
446 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
159 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
3k 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
1k 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?
...
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'...
0
votes
1answer
76 views
Finding time complexity of my solution to the 'longest palindrome' problem in Python
Here is a short version!
...
2
votes
2answers
8k 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.
...
1
vote
2answers
2k 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 ...
3
votes
2answers
3k 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
989 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: ...
7
votes
2answers
2k 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:
...