Wednesday, 1 Dec 2021
Category: palindrome

Given a string S consisting of N characters, the task is to check if this string has an reversible equal substring from the start and the end. If yes, print True and then the longest substring present following the given conditions, otherwise print False.Example:Input: S = “abca”Output: TrueaExplanation:The substring “a”  is only the longest substring that […]

#include using namespace std;  int minimumPalindromicStrings(string S){        int N = S.length();                      vector freq(26);    for (int i = 0; i < N; i++) {        freq[S[i] - 'a']++;    }          vector oddFreqCharacters;                                for (int i = 0; i < 26; i++) {          if (freq[i] & 1) {              oddFreqCharacters.push_back(i);            freq[i]--;        }          freq[i] /= 2;    }          vector ans;              if (oddFreqCharacters.empty()) {                          string left = "";          for (int i = 0; i < 26; i++) {            for (int j = […]

How to check whether a passed string is palindrome or not in JavaScript ?Given a string, our task is to find string is palindrome or not.Example: Input : “race” Output : passed string is not a palidrome Explanation : if we write “race” in reverse that is “ecer” it not matches with first string so […]

Modify a sentence by reversing order of occurrences of all Palindrome WordsGiven a string S representing a sentence, the task is to reverse the order of all palindromic words present in the sentence.Examples:Input: S = “mom and dad went to eye hospital”Output: eye and dad went to mom hospitalExplanation: All palindromic words present in the […]

import java.io.*;import java.util.HashMap;import java.util.HashSet;import java.util.Map;  class GFG {              public static boolean    canBecomePalindromeUtil(String S,                            String B)    {                        HashSet set = new HashSet();                  for (int i = 0; i < S.length(); i++) {                          set.add(S.charAt(i));        }                          HashMap map            = new HashMap();                  for (int i = 0; i < S.length(); i++) {            Integer k = map.get(S.charAt(i));            map.put(S.charAt(i),                    (k == null) ? 1 : k + 1);        }          boolean flag = false;                  if (S.length() % 2 == 1) […]

Rearrange characters of a string to make it a concatenation of palindromic substrings Given a string S consisting of lowercase alphabets, the task is to check whether the given string can be rearranged such that the string can be split into non-overlapping palindromic substrings of at least length 2. If found to be true, then […]

#include using namespace std;    struct Node {     char data;     Node *left, *right; };    Node* newNode(char data) {     Node* temp = new Node();     temp->data = data;     temp->left = temp->right = NULL;     return temp; }    bool checkPalindrome(string s) {     int low = 0, high = (int)s.size() – 1;        while (low < high) […]