Computer Science, asked by singhyuvraj13681, 1 year ago

What's a (1:1) if a is a string of at least two characters? And what if string is shorter.

Answers

Answered by Anonymous
10

Answer:

=>Given 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.

=>Examples :

Input: str1 = "AXY", str2 = "ADXCPY"

Output: True (str1 is a subsequence of str2)

Input: str1 = "AXY", str2 = "YADXCP"

Output: False (str1 is not a subsequence of str2)

Input: str1 = "gksrek", str2 = "geeksforgeeks"

Output: True (str1 is a subsequence of str2)

Recommended=> Please solve it on “PRACTICE ” first, before moving on to the solution.

The idea is simple, we traverse both strings from one side to other side (say from rightmost character to leftmost). If we find a matching character, we move ahead in both strings. Otherwise we move ahead only in str2.

Similar questions