Given a string str, the task is to find the maximum length K such that there exist two sub-sequences A and B each of length K such that A = B and number of common indices between A and B is at most K – 1.
Input: str = “geeksforgeeks”
The two subsequences are
str[0…1] + str[3…12] = “geksforgeeks”
and str + str[2…12] = “geksforgeeks”.
Input: str = “abcddefg”
Approach: Find any pair of the same letter with a minimum number of letters between them let say this minimum number be X, now the answer of the problem is len(str) – (X + 1). One is added in X to not take count of one letter from the pair.
Below is the implementation of the above approach:
Time Complexity: O(n) where n is the length of the input string.
- Count the number of subsequences of length k having equal LCM and HCF
- Number of subsequences of maximum length K containing no repeated elements
- Find all combinations of two equal sum subsequences
- Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
- Minimum index i such that all the elements from index i to given index are equal
- Program to find the maximum difference between the index of any two different numbers
- Sum of all subsequences of length K
- Find subarray of Length K with Maximum Peak
- Find the first maximum length even word from a string
- Find maximum sum possible equal sum of three stacks
- Find three integers less than or equal to N such that their LCM is maximum
- Unique subsequences of length K with given sum
- Find Maximum Length Of A Square Submatrix Having Sum Of Elements At-Most K
- Find the Increasing subsequence of length three with maximum product
- Find four factors of N with maximum product and sum equal to N | Set 3
- Number of K length subsequences with minimum sum
- Number of palindromic subsequences of length k where k <= 3
- Count of subsequences of length 4 in form (x, x, x+1, x+1) | Set 2
- Count unique subsequences of length K
- Count of possible subarrays and subsequences using given length of Array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.