@@ -0,0 +1,2239 @@
+package com.sunny.grokkingalgorithms.boot2019.phleps;%0A%0Apublic class StringSubsequenceProblem %7B%0A%0A    /*%0A    Given two strings, find if first string is a subsequence of second%0AGiven two strings str1 and str2, find if str1 is a subsequence of str2. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements (source: wiki). Expected time complexity is linear.%0A%0AExamples :%0A%0AInput: str1 = %22AXY%22, str2 = %22ADXCPY%22%0AOutput: True (str1 is a subsequence of str2)%0A%0AInput: str1 = %22AXY%22, str2 = %22YADXCP%22%0AOutput: False (str1 is not a subsequence of str2)%0A%0AInput: str1 = %22gksrek%22, str2 = %22geeksforgeeks%22%0AOutput: True (str1 is a subsequence of str2)%0A     */%0A%0A    public static boolean isSubsequence(String subsequence,String str)%7B%0A        boolean isSubsequence = false;%0A        for(int i = 0 ; i %3C str.length() ; i++)%7B%0A            char current = str.charAt(i);%0A            if(current == subsequence.charAt(0))%7B%0A                isSubsequence = doesStringContainSubsequence(str,i,subsequence);%0A                if(isSubsequence)%7B%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A        return isSubsequence;%0A    %7D%0A%0A    public static boolean doesStringContainSubsequence(String str,int index,String subsequence)%7B%0A        int matchCount = 0;%0A        boolean isSubsequence = false;%0A        int subIndex = 0;%0A        int strIndex = index;%0A        while(strIndex %3C str.length()%0A                && subIndex %3C subsequence.length())%7B%0A            if(str.charAt(strIndex) == subsequence.charAt(subIndex))%7B%0A                matchCount++;%0A                subIndex++;%0A            %7D%0A            strIndex++;%0A        %7D%0A        if(matchCount == subsequence.length())%7B%0A            isSubsequence = true;%0A        %7D%0A        return isSubsequence;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        String subsequence = %22AXY%22;%0A        String str = %22ADXCPY%22;%0A        System.out.println(isSubsequence(subsequence,str));%0A        subsequence = %22AXY%22;%0A        str = %22YADXCP%22;%0A        System.out.println(isSubsequence(subsequence,str));%0A        subsequence = %22gksrek%22;%0A        str = %22geeksforgeeks%22;%0A        System.out.println(isSubsequence(subsequence,str));%0A    %7D%0A%0A%7D%0A

Check if a string is asubsequence to another , brute force.