Techno Blender
Digitally Yours.
Browsing Tag

Substring

Convert s1 into a Palindrome such that s1 contains s2 as Substring

Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contains s2 as a substring in a… Read More The post Convert s1 into a Palindrome such that s1 contains s2 as Substring appeared first on GeeksforGeeks. Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contains s2 as a substring in a… Read More The post Convert s1 into a Palindrome such that s1 contains s2 as Substring appeared first on GeeksforGeeks. FOLLOW US ON GOOGLE NEWS Read original…

Find the longest Substring of a given String S

import java.io.*;import java.util.*;  public class GFG {              public static void maxLength(int lis, int n)    {        long or = 0;                          for (int i = 0; i < n; i++) {            or |= lis;        }          int count = new int;        for (int i = 0; i < n; i++) {            for (int j = 0; j < 32; j++) {                if ((lis & (1L << j)) != 0)                    count++;            }        }          long ans = 0, l = 0, tempOr = 0;        for (int r = 0; r < n; r++)…

Longest Palindromic Substring using hashing in O(nlogn)

#include <bits/stdc++.h>using namespace std;  string longestPalindromicSubstring(string S){              int n = S.length();    int hash_table;    memset(hash_table, 0, sizeof(hash_table));    bool isPalindrome = true;                  for (int i = 0; i < n; i++)        hash_table - 'a'] = i;              int start = 0, end = 0;              for (int i = 0; i < n; i++) {                          if (hash_table - 'a'] > 0) {                        int len = hash_table - 'a'] - i;…

Count ways to generate Binary String not containing “0100” Substring

Improve Article Save Article Like Article Improve Article Save Article Given the number N, count the number of ways to create a binary string (the string that contains characters as zero or one) of size N such that it does not contain “0100” as a substring.  A substring is a contiguous sequence of characters within a string.Examples: Input: N = 4Output: 15Explanation: The answer will contain all possible substrings of size 4 except 0100 itself.Input: N = 5Output: 28Naive approach: The article can be solved based on…

Check if String T can be made Substring of S by replacing given characters

  #include <bits/stdc++.h>using namespace std;  bool match(string S, string T,           vector<vector<char> >& replace){                unordered_map<char, unordered_set<char> > unmap;    int m = S.size(), n = T.size();              for (auto c : replace) {        unmap].insert(c);    }              for (int i = 0; i < m - n + 1; i++) {        bool flag = true;        for (int j = 0; j < n; j++) {                                                                          if (S != T)…

Get a Substring in C

Given a string str and pos and len that defines the starting and the length of the subarray. The task is to generate a substring of size len starting from the index pos. A substring is a contiguous sequence of characters within a String.Examples:Input: Str =”the”, pos=1, len=2Output:  “th”Explanation: substrings will be: “”, “t”, “h”, “e”, “th”, “he”, “the”.Input: Str =”geeks”, pos=3, length=3Output: “eks” Explanation: substrings are: “”, ” g”, “e”, “e”, “k”, “s”, “ge”, “ee”, “ek”, “ks”, “gee”, “eek”, “eks”, “geek”,…

Longest Subtring of A that can be changed to Substring of B in at most T cost

#include <bits/stdc++.h>using namespace std;  int startPos = -1, endPos = -1;  bool isValid(int len, string& A, string& B, int K, int T){    int i = 0, j = 0, n = A.size(), cost = 0;                      bool flag = false;      while (j < n) {                          cost += ((A != B) ? K : 0);                          if (j - i + 1 == len) {                                                              if (cost <= T) {                flag = true;                startPos = i;                endPos = j;…