Tag Archives: Substring

Find length of Longest Consecutive Occurrences of second string that occurs in first string

You are given two strings string1 and string2. Your task is to find length of longest consecutive occurrences of second string that occurs in first string. Examples: Input: string1=”AAACBBAAAA”,  string2=”A” Output: 4 Explanation: We will get AAA(0:3) and then AAAA(6:10) as 4 is greater than 3, answer is 4. Input: string1=”ABBABBABBAAAA”,  string2=”ABB” Output: 9 Approach: Initially find length… Read More »

Smallest window in a String containing all characters of other String

Given two strings string1 and string2, the task is to find the smallest substring in string1 containing all characters of string2. Examples : Input: string = “Cplusplus is the best”, pattern = “pp” Output: Smallest window is : plusp Explanation: “plusp” contains all the characters of pattern. Input: string = “Cplusplus”, pattern = “Cpp” Output: Smallest window is… Read More »