Wednesday, 1 Dec 2021
Category: substring

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 […]

Check if a numeric string can be split into substrings having difference between consecutive numbers equal to KGiven a numeric string S consisting of N digits and a positive integer K, the task is to check if the given string can be split into more than one substrings with difference between consecutive substrings equalt to […]

import java.io.*;import java.util.*;  class GFG {                  static int count(String S, int N)    {                  char ch[] = { ‘u’, ‘o’, ‘i’, ‘e’, ‘a’ };                  int j = 0;                  int res = 0;                          int count = 0;                  HashSet mp = new HashSet();                  for (int i = 0; i < N; ++i) {                          if (S.charAt(i) == ch[j]) {                                  ++count;                                  mp.add(S.charAt(i));                                  if (mp.size() == 5) {                    res = Math.max(res, count);                }            }                                      else if (j + […]

#include using namespace std;void update(int ind, vector& segTree,            int n){        ind += n;        segTree[ind]++;    for (; ind > 1; ind >>= 1) {                segTree[ind >> 1] = segTree[ind]                            + segTree[ind ^ 1];    }}int query(int low, int high,          vector& segTree, int n){            low += n;    high += n;    int ans = 0;    while (low < high) {                        if (low % 2) {            ans += segTree[low];            low++;        }        if (high % 2) {            high--;            ans += […]

Count occurrences of substring X before every occurrence of substring Y in a given stringGiven three strings S, X, and Y consisting of N, A, and B characters respectively, the task is to find the number of occurrences of the substring X before every occurrence of the substring Y in the given string S.Examples:Input S […]

Number of substrings having an equal number of lowercase and uppercase lettersGiven string S consisting of lowercase and uppercase letters, the task is to find the number of substrings having the equal number of lowercase and uppercase letters.Examples:Input: S = “gEEk”Output: 3Explanation:Following are the substrings having the equal number of lowercase and uppercase letters:“gE”“gEEk”“Ek”Therefore, the […]

Minimize length of a string by removing pairs of consecutive increasing or decreasing digitsGiven a numeric string S consisting of N digits, the task is to find the minimum length of the string that can be formed by repeatedly removing pairs of adjacent consecutive characters arranged in either increasing or decreasing order.Examples:Input: S = “12213”Output: […]