Given two strings A and B, find if A is a subsequence of B.
Example 1:
Input:
A = AXY 
B = YADXCP
Output: 0 
Explanation: A is not a subsequence of B
as 'Y' appears before 'A'.
 
Example 2:
Input:
A = gksrek
B = geeksforgeeks
Output: 1
Explanation: A is a subsequence of B.
 
Your Task:  
You dont need to read input or print anything. Complete the function isSubSequence() which takes A and B as input parameters and returns a boolean value denoting if A is a subsequence of B or not. 
 
Expected Time Complexity: O(N) where N is length of string B.
Expected Auxiliary Space: O(1)
Constraints:
1<= |A|,|B| <=10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



class Solution:

    def isSubSequence(self, A, B):

        #code here

Solutions:
class Solution:

	def isSubSequence(self, A, B):
		curr = 0
		for i in B:
			if i == A[curr]:
				curr += 1
			if curr == len(A):
				return True
		return False


class Solution:

	def isSubSequence(self, A, B):
		i = 0
		j = 0
		while j < len(B) and i < len(A):
			if A[i] == B[j]:
				i += 1
			j += 1
		if i == len(A):
			return 1
		else:
			return 0


class Solution:

	def isSubSequence(self, A, B):
		(ind, count) = (0, 0)
		for i in range(len(B)):
			if A[ind] == B[i]:
				ind += 1
				count += 1
			if ind > len(A) - 1:
				break
		if count == len(A):
			return 1
		return 0


class Solution:

	def isSubSequence(self, a, b):
		(i, j) = (0, 0)
		while i < len(a) and j < len(b):
			if a[i] == b[j]:
				i += 1
				j += 1
			else:
				j += 1
		if i < len(a):
			return 0
		return 1


class Solution:

	def isSubSequence(self, A, B):
		j = 0
		for i in range(len(B)):
			if B[i] == A[j]:
				j += 1
				if j == len(A):
					return 1
		return 0


class Solution:

	def isSubSequence(self, A, B):

		def get_result(a, b):
			value = 0
			d = 0
			for i in range(len(B)):
				if b[i] == a[d]:
					d += 1
					if d == len(A):
						return 1
			return 0
		result = get_result(A, B)
		return result


class Solution:

	def isSubSequence(self, A, B):
		for i in A:
			if i not in B:
				return False
			x = B.index(i)
			B = B[x + 1:]
		return True


class Solution:

	def isSubSequence(self, A, B):
		n = len(A)
		m = len(B)
		i = 0
		j = 0
		while i < n and j < m:
			if A[i] == B[j]:
				i += 1
			j += 1
		return i == n


class Solution:

	def isSubSequence(self, B, A):
		i = 0
		j = 0
		while i < len(A) and j < len(B):
			if A[i] == B[j]:
				j = j + 1
			i = i + 1
		if j != len(B):
			return False
		return True


class Solution:

	def isSubSequence(self, A, B):
		left = 0
		count = 0
		for i in A:
			while left < len(B):
				if B[left] == i:
					count += 1
					left += 1
					break
				else:
					left += 1
		return count == len(A)


class Solution:

	def isSubSequence(self, A, B):
		for i in A:
			c = B.find(i)
			if c == -1:
				return 0
			else:
				B = B[c + 1:]
		return 1


class Solution:

	def isSubSequence(self, a, b):
		p = 0
		for i in b:
			if a[p] == i:
				p = p + 1
			if len(a) == p:
				return 1
		else:
			return 0


class Solution:

	def isSubSequence(self, A, B):
		ans = ''
		i = 0
		j = 0
		while i < len(B):
			if j < len(A):
				if B[i] == A[j]:
					ans += B[i]
					j += 1
			i += 1
		return ans == A


class Solution:

	def isSubSequence(self, A, B):
		i = 0
		j = 0
		lenA = len(A)
		lenB = len(B)
		while i < lenA and j < lenB:
			if A[i] == B[j]:
				i += 1
			j += 1
		return i == len(A)


class Solution:

	def isSubSequence(self, A, B):
		left = 0
		right = 0
		while left < len(A) and right < len(B):
			if A[left] == B[right]:
				left += 1
			right += 1
		if left == len(A):
			return 1
		return 0


class Solution:

	def isSubSequence(self, A, B):
		c = 0
		d = 0
		while c < len(A) and d < len(B):
			if A[c] == B[d]:
				c += 1
			d += 1
		if c == len(A):
			return 1
		return 0


class Solution:

	def isSubSequence(self, A, B):
		j = 0
		for i in B:
			if i == A[j]:
				j += 1
				if j == len(A):
					break
		if j == len(A):
			return 1
		else:
			return 0


class Solution:

	def isSubSequence(self, A, B):
		s = 0
		for i in B:
			if A[s] == i:
				s += 1
			if len(A) == s:
				return 1
		if len(A) == s:
			return 1
		else:
			return 0


class Solution:

	def isSubSequence(self, A, B):
		for i in A:
			if i in B:
				B = B[B.index(i) + 1:]
			else:
				return False
		return True


class Solution:

	def isSubSequence(self, A, B):
		j = 0
		for i in range(len(B)):
			if j < len(A):
				if B[i] == A[j]:
					j += 1
				else:
					continue
		if j == len(A):
			return True
		else:
			return False


class Solution:

	def isSubSequence(self, A, B):
		len1 = len(A)
		len2 = len(B)
		i = 0
		j = 0
		while i < len1 and j < len2:
			if A[i] == B[j]:
				i += 1
			j += 1
		return i == len1


class new:

	def check(self, s, temp):
		t = 0
		if s[t] in temp:
			x = True
		else:
			x = False
			return False
		y = temp.index(s[t])
		temp = temp[y + 1:]
		s = s[t + 1:]
		if len(s) == 0:
			return x
		return check(s, temp)

class Solution:

	def isSubSequence(self, A, B):
		t = 0
		if A[t] in B:
			x = True
		else:
			x = False
			return False
		y = B.index(A[t])
		B = B[y + 1:]
		A = A[t + 1:]
		if len(A) == 0:
			return x
		return ob.isSubSequence(A, B)


class Solution:

	def isSubSequence(self, A, B):
		count = 0
		li = []
		for i in range(len(A)):
			if A[i] in B[count:]:
				a = B.index(A[i], count)
				count = a + 1
				li.append(a)
			else:
				break
		if len(li) == len(A):
			return True
		else:
			return False


class Solution:

	def isSubSequence(self, A, B):
		new_string = B[:]
		for char in A:
			if char in new_string:
				index_char = new_string.index(char)
				new_string = new_string[index_char + 1:]
			else:
				return False
		return True