Category : palindrome

class Solution { public: string longestPalindrome(string s) { int n=s.length(); int table[n][n]; memset(table,0,sizeof(table)); //length 1 int i,j,k; for(i=0;i<n;i++) table[i][i]=1; int maxlength=1; int start; //length 2 for(i=0;i<n-1;i++){ if(s[i]==s[i+1]){ table[i][i+1]=1; maxlength=2; start=i; } } //length>=3 for(k=3;k<=n;k++){//k->length for(i=0;i<n-k+1;i++){//i->starting index j=i-k+1;//j->ending index of substring if(s[i]==s[j] && table[i+1][j-1]==1){ table[i][j]=1; start=i; maxlength=k; } } } return s.substr(i,i+maxlength); } }; This code ..

Read more

The following is the code of an nth even length palindrome, but i wanted to know the code for nth odd length palindrome. Ps. don’t downvote if you don’t know the answer. #include <bits/stdc++.h> using namespace std; // Function to find nth even length Palindrome string evenlength(string n) { // string r to store resultant ..

Read more

Write a program that initialize array of size 10, and prints all palindrome number in array The code so far: #include<iostream> using namespace std; int main() { int myarray[10], t, remainder, i, reversenum = 0; cout << "Enter values:" << endl; for (i = 0; i < 10; i++) { cin >> myarray[i]; t = ..

Read more

i made this program to make a function to check if integar array is palindrome or not.it is always giving output that it is not a palidrome on every input. can you plz help me out? code: #include<iostream> using namespace std; void palindrome(int[],int[],int); int main() { int size=5; int array1[size]; int array2[size]; palindrome(array1,array2,size); } void ..

Read more