26. Check if a String is Subsequence of Other
β GFG solution to check if one string is a subsequence of another using efficient two-pointer technique. Find if s1 is subsequence of s2 optimally. π
π§© Problem Description
π Examples
Example 1
Input: s1 = "AXY", s2 = "YADXCP"
Output: false
Explanation: s1 is not a subsequence of s2 as 'Y' appears before 'A' in s2,
but in s1, 'A' comes before 'Y'.Example 2
Input: s1 = "gksrek", s2 = "geeksforgeeks"
Output: true
Explanation: If we combine the bold characters of "g**e**e**k**sfor**g**ee**k**s",
it gives us "geksrek". We can derive "gksrek" by removing one 'e', making s1 a subsequence of s2.Example 3
π Constraints
β
My Approach
Two Pointer Greedy Algorithm
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Previous25. Maximize Median After K Addition OperationsNext27. Count the Number of Possible Triangles
Last updated