Techno Blender
Digitally Yours.
Browsing Tag

Substrings

Find number of contiguous Substrings with repeated patterns

Improve Article Save Article Like Article Improve Article Save Article Like Article Given a string str consisting of digits, the task is to find the number of contiguous substrings such that the substring can be rearranged into a repetition of some string twice.Examples:Input:  str=”15512212″Output: 6Explanation: Possible 6 substrings are : “1551” can be rearranged to “1515““155122” can be rearranged to “152152““551221” can be rearranged to “512512““1221” can be rearranged to “1212““55” can be  rearranged to…

Check if N sized String with given number of 00, 01, 10, 11 Substrings exists

Given an integer N and four values a, b, c, d (where a ≥ 0, b ≥ 0, c ≥ 0, d ≥ 0), the task is to check if it is possible to create a binary string of length N such that:There are exactly a substrings of “00” There are exactly b substrings of “01”There are exactly c substrings of “10”There are exactly d substrings of “11”Examples:Input:  N = 11, a = 2, b = 3, c = 3, d = 2Output : Yes Explanation : In this string, exactly 2 numbers of 00, exactly 3 numbers 01, exactly 3 numbers of 10 and exactly 2 numbers of 11.Input : N =…

Find the number of Substrings with even number of K

Given a string str of length N and an integer K, the task is to count the number of substrings with even numbers of K.… Read More The post Find the number of Substrings with even number of K appeared first on GeeksforGeeks. Given a string str of length N and an integer K, the task is to count the number of substrings with even numbers of K.… Read More The post Find the number of Substrings with even number of K appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE NEWS Read original article here Denial of…

Split Strings into two Substrings whose distinct element counts are equal

Improve Article Save Article Like Article Improve Article Save Article Given a string S of length N, the task is to check if a string can be split into two non-intersecting strings such that the number of distinct characters are equal in both.Examples:Input: N = 6, S = “abccba”Output: TrueExplanation: Splitting two strings as “abc” and “cba” has 3 distinct characters each.Input: N = 5, S = “aacaa”Output: FalseExplanation: Not possible to split it into two strings of the same distinct characters.Approach: To solve the…

Count all palindromic Substrings for each character in a given String

Improve Article Save Article Like Article Improve Article Save Article Given a string S of length n, for each character S, the task is to find the number of palindromic substrings of length K such that no substring should contain S, the task is to return an array A of length n, where A is the count of palindromic substrings of length K which does not include the character S.Examples:Input: S = “aababba”, K = 2Output : A = Explanation: A = 1 => removing char s = ‘a’ only one palindromic substring of length 2 is…

Print all Substrings of a String that has equal number of vowels and consonants

Improve Article Save Article Like Article Improve Article Save Article Given a string S, the task is to print all the substrings of a string that has an equal number of vowels and consonants.Examples:Input: “geeks”Output: “ge”, “geek”, “eeks”, “ek”Input: “coding”Output: “co”, “codi”, “od”, “odin”, “di”, “in”Naive Approach: The basic approach to solve this problem is to generate all the substrings and then for each substring count the number of vowels and consonants present in it. If they are equal print it. Time…

Print all Substrings of length n possible from the given String

Given a string str and an integer N, the task is to print all possible sub-strings of length N.Examples:Input: str = “geeksforgeeks”, N = 3Output: gee eek eks ksf sfo for org rge gee eek eksExplanations: All possible sub-strings of length 3 are “gee”, “eek”, “eks”, “ksf”, “sfo”, “for”, “org”, “rge”, “gee”, “eek” and “eks”.Input: str = “GFG”, N = 2 Output: GF FGExplanations: All possible sub-strings of length 2 are “GF”, “FG”Method 1: Using slicingApproach: To solve the problem follow the below steps:Initialize a variable…

Count ways to select two N sized Substrings differing by one letter

Given a string str, the task is to find the number of ways two non-overlapping substrings of length N can be selected out of a string that differs by just one letter.Examples:Input: str = “abcd”, N = 1Output: 6Explanation: Possible non overlapping substrings pairs are (“a”, “b”), (“b”, “c”), (“c”, “d”), (“a”, “c”), (“a”, “d”) and (“b”, “d”).Input: str = “abcb”, N = 2Output: 1Explanation: The only possible substring pair is (“ab”, “cb”).Naive Approach: To solve the problem follow the below idea:The approach is to find the…

Create a string with unique characters from the given N substrings

  #include <bits/stdc++.h>using namespace std;  void formedString(int n, vector<string>& arr){                  vector<int> left(26), right(26);                      for (int i = 0; i < 26; i++)        left = right = -2;      for (string s : arr) {                          for (int j = 0; j < s.size(); j++) {                                      int t = s - 'a';                                                  if (j > 0) {                int t1 = s - 'a';                left = t1;…

Minimum moves to make String Palindrome incrementing all characters of Substrings

  import java.io.*;import java.util.*;  public class GFG {              public static void minMoves(int a, int n)    {        int b = new int;        for (int i = 0; i < n; i++) {            if (a > a) {                b = a - a;            }        }        long ans = b;        for (int i = 1; i < n; i++) {            ans += Math.max(0, b - b);        }        System.out.println(ans);    }          public static void main(String args)    {                String S1 = "2643";        int N = S1.length();        int…