Category Archives: Data Structures

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 »

Sort odd indices in ascending order and even indices in descending order of the string

Given a string S, the task is to sort odd indices in ascending order and even indices in descending order of the string. Examples: Input: S = “Cplusplus” Output: Cululspsp Explanation: Sort string S in ascending order: S = “Cululspsp” Replace odd indices in ascensing order and even indices in descending order. Input: S = “plusplus” Output: lulupsps… Read More »