Given a string S, check whether it can be converted into the string "hello" by deleting some characters from it.
Note : S can have both uppercase and lowercase letters.
Example 1:
Input:
S = "bbbbbxxhhelllllooudd"
Output: 1
Explanation: The string hello is marked
in bold: bbbbbxxhhelllllooudd
Ã¢â¬â¹Example 2:
Input: 
S = "hlelo"
Output: 0
Explanation: It's impossible to convert
the given string into "hello".
Your Task:
You don't need to read input or print anything. Your task is to complete the function decode() which takes the string S as input and returns the true if the string can be converted to "hello", else return false.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1<=|S|<=10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Amortized analysis

Starter code: #User function Template for python3

class Solution:

    def decode(self, S):
        # code here

Solutions:
class Solution:

	def decode(self, S):
		lp = 'hello'
		j = 0
		for i in range(len(S)):
			if s[i] == lp[j]:
				j += 1
			if j == len(lp):
				return 1
		return 0


class Solution:

	def decode(self, S):
		l = []
		j = 0
		for i in S:
			if i in ('h', 'e', 'l', 'o'):
				l.append(i)
		for i in l:
			if j == 0 and i == 'h':
				j += 1
			elif j == 1 and i == 'e':
				j += 1
			elif (j == 2 or j == 3) and i == 'l':
				j += 1
			elif j == 4 and i == 'o':
				j += 1
				break
		if j == 5:
			return True
		else:
			return False


class Solution:

	def decode(self, s):
		n = len(s)
		s1 = 'hello'
		j = 0
		for i in range(n):
			if j < 5:
				if s[i] == s1[j]:
					j += 1
		if j == 5:
			return True
		return False


class Solution:

	def decode(self, S):
		h = ['h', 'e', 'l', 'l', 'o']
		for i in S:
			if i == h[0]:
				h.pop(0)
				if len(h) == 0:
					return True
					break
		return False


class Solution:

	def decode(self, S):
		res = 'hello'
		j = 0
		for i in S:
			if i == res[j]:
				j += 1
			if j == len(res):
				return 1
		return 0


class Solution:

	def decode(self, S):
		x = 'hello'
		start = 0
		for i in S:
			if i == x[start]:
				start += 1
			if start == len(x):
				return True
		return False


class Solution:

	def decode(self, S):
		x = ['h', 'e', 'l', 'l', 'o']
		start = 0
		for i in S:
			if i == x[start]:
				start += 1
			if start == len(x):
				return True
		return False


class Solution:

	def decode(self, S):
		s1 = 'hello'
		j = 0
		for i in range(len(S)):
			if S[i] == s1[j]:
				j += 1
			if j == len(s1):
				break
		if j == len(s1):
			return True
		else:
			return False


class Solution:

	def decode(self, S):
		s = 'hello'
		count = 0
		for i in S:
			if i == s[count]:
				count += 1
				if count == 5:
					return 1
		return 0


class Solution:

	def decode(self, S):
		string = 'hello'
		j = 0
		for i in range(len(S)):
			if S[i] == string[j]:
				j = j + 1
				if j == 5:
					return 1
		return 0


class Solution:

	def decode(self, s):
		l = list(s)
		if 'h' in l:
			l = l[l.index('h') + 1:]
		else:
			return 0
		if 'e' in l:
			l = l[l.index('e') + 1:]
		else:
			return 0
		if 'l' in l:
			l = l[l.index('l') + 1:]
		else:
			return 0
		if 'l' in l:
			l = l[l.index('l') + 1:]
		else:
			return 0
		if 'o' in l:
			l = l[l.index('o') + 1:]
		else:
			return 0
		return 1


class Solution:

	def decode(self, S):
		s = 'hello'
		j = 0
		a = ''
		for i in S:
			if j >= len(s):
				break
			if i == s[j]:
				a += i
				j += 1
		if a == s:
			return 1
		else:
			return 0


class Solution:

	def decode(self, S):
		stack = list('hello')
		for i in S:
			if i == stack[0]:
				stack.pop(0)
				if not stack:
					return 1
		return 0


class Solution:

	def decode(self, S):
		checkStr = 'hello'
		for i in range(len(S)):
			if S[i] == checkStr[0] and len(checkStr) > 1:
				checkStr = checkStr[1:]
			elif S[i] == checkStr[0] and len(checkStr) == 1:
				return 1
		return 0


class Solution:

	def decode(self, S):
		S.lower()
		r = ''
		x = 'hello1'
		m = 0
		p = x[0]
		for i in range(len(S)):
			if S[i] == p:
				r += S[i]
				m += 1
				p = x[m]
		n = len(x) - 1
		if r == x[0:n]:
			return 1
		else:
			return 0


class Solution:

	def decode(self, S):
		word = 'hello'
		pnt1 = 0
		pnth = 0
		while True:
			if S[pnt1] == word[pnth]:
				pnth += 1
				pnt1 += 1
			else:
				pnt1 += 1
			if pnth == 5:
				return True
			if pnt1 == len(S):
				return False


class Solution:

	def decode(self, S):
		a = 'hello'
		b = 0
		for i in range(len(S)):
			if a[b] == S[i]:
				b = b + 1
				if b == 5:
					break
		if len(a) == b:
			return 1
		return 0


class Solution:

	def decode(self, S):
		hello = list('hello')
		stack = list(S)
		while hello and stack:
			if hello[-1] == stack[-1]:
				hello.pop()
			stack.pop()
		return not hello


class Solution:

	def decode(self, S):
		index = 0
		h = 'hello'
		for i in S:
			if i == h[index]:
				index += 1
			if index == 5:
				return 1
		return 0


class Solution:

	def decode(self, S):
		h = 'hello'
		j = 0
		for i in S:
			if i == h[j]:
				j += 1
			if j == len(h):
				return True
		return False


class Solution:

	def decode(self, S):
		s = 'hello'
		k = 0
		for i in range(len(S)):
			if S[i] == s[k]:
				k += 1
			if k == len(s):
				return True
		return False


class Solution:

	def decode(self, S):
		S.lower()
		l = ['h', 'e', 'l', 'l', 'o']
		x = 0
		for i in S:
			if x < 5:
				if i is l[x]:
					x += 1
		if x == 5:
			return True
		return False


class Solution:

	def decode(self, S):
		c = ['h', 'e', 'l', 'l', 'o']
		for i in S:
			if i == c[0]:
				c.pop(0)
			if len(c) == 0:
				return 1
		return 0


class Solution:

	def decode(self, S):
		S.lower()
		a = ['h', 'e', 'l', 'l', 'o']
		for i in S:
			if i == a[0]:
				a.pop(0)
				if len(a) == 0:
					return 1
		else:
			return 0


class Solution:

	def decode(self, S):
		m = 'hello'
		j = 0
		k = 0
		s1 = ''
		for i in range(len(S)):
			t = m[j]
			if S[i] == t:
				j += 1
				s1 += S[i]
				if s1 == m:
					k = 1
					break
		if k == 0:
			return 0
		else:
			return 1


class Solution:

	def decode(self, S):
		find = 'hello'
		(i, j) = (0, 0)
		n = len(S)
		while i < n:
			if S[i] == find[j]:
				j += 1
				if j == 5:
					return 1
			i += 1
		return 0


class Solution:

	def decode(self, S):
		n = 'hello'
		j = 0
		for i in range(len(S)):
			if S[i] == n[j]:
				j = j + 1
			if j == len(n):
				break
		return len(n) == j


class Solution:

	def decode(self, S):
		x = ''
		c = 'hello'
		j = 0
		for i in c:
			while j < len(S):
				if S[j] == i:
					x += S[j]
					break
				j += 1
			j += 1
		if x == c:
			return True
		return False


class Solution:

	def decode(self, S):
		stack = list('olleh')
		for c in S:
			if stack and c == stack[-1]:
				stack.pop()
			if not stack:
				return 1
		return 0


class Solution:

	def decode(self, S):
		v = 'hello'
		i = 0
		j = 0
		while i < len(v) and j < len(S):
			if S[j] == v[i]:
				i += 1
			j += 1
		if len(v) == i:
			return 1
		else:
			return 0


class Solution:

	def decode(self, S):
		req = [0] * 5
		hello = 'hello'
		i = 0
		for x in range(len(S)):
			if i == 5:
				break
			if S[x] == hello[i]:
				req[i] = True
				i += 1
		return all(req)


class Solution:

	def decode(self, S):
		s = 'hello'
		j = 0
		ct = 0
		for i in S:
			if i == s[j]:
				j += 1
				if j == 5:
					return 1
		return 0


import re

class Solution:

	def decode(self, S):
		key = 'hello'
		i = j = 0
		for i in range(len(S)):
			if S[i] == key[j]:
				j += 1
				if j == 5:
					return True
			i += 1
		return False


class Solution:

	def decode(self, S):
		x = 'hello'
		t = 0
		for i in S:
			if i == x[t]:
				t += 1
			if t == 5:
				return True
		return False
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.decode(s)
		if ans:
			print(1)
		else:
			print(0)


class Solution:

	def decode(self, S):
		a = 'hello'
		j = 0
		for i in range(len(S)):
			if S[i] == a[j]:
				j += 1
				if j == 5:
					return 1
			else:
				continue
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.decode(s)
		if ans:
			print(1)
		else:
			print(0)


class Solution:

	def decode(self, S):
		word = 'hello'
		n = len(word)
		i = 0
		for ele in S:
			if ele == word[i]:
				i += 1
				if i == n:
					return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.decode(s)
		if ans:
			print(1)
		else:
			print(0)


class Solution:

	def decode(self, S):
		m = 'hello'
		k = 0
		for i in S:
			if i == m[k]:
				k += 1
			if k == 5:
				return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.decode(s)
		if ans:
			print(1)
		else:
			print(0)


class Solution:

	def decode(self, S):
		lst = list(S)
		string = 'hello'
		for itr in range(len(string)):
			if string[itr] in lst:
				lst = lst[lst.index(string[itr]) + 1:]
			else:
				return False
		return True
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.decode(s)
		if ans:
			print(1)
		else:
			print(0)


class Solution:

	def decode(self, S):
		st = 'hello'
		i = 0
		j = 0
		c = 0
		while j < len(S):
			if c == 5:
				break
			if S[j] == st[i]:
				i += 1
				c += 1
				j += 1
			else:
				j += 1
		return 1 if c == 5 else 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.decode(s)
		if ans:
			print(1)
		else:
			print(0)


class Solution:

	def decode(self, S):
		s = 'hello'
		i = 0
		j = 0
		while i < len(S) and j < 5:
			if s[j] == S[i]:
				j = j + 1
			i = i + 1
		if j == 5:
			return 1
		return 0


class Solution:

	def decode(self, S):
		p1 = 0
		p2 = 0
		find = 'hello'
		n = len(S)
		while p1 < n:
			if S[p1] == find[p2]:
				p2 = p2 + 1
			if p2 == 5:
				return 1
			p1 = p1 + 1
		return 0


class Solution:

	def decode(self, S):
		p1 = 0
		p2 = ['h', 'e', 'l', 'l', 'o']
		n = len(S)
		for i in S:
			if len(p2) and i == p2[0]:
				p2.pop(0)
		if len(p2):
			return 0
		else:
			return 1


class Solution:

	def decode(self, S):
		t = 'hello'
		(i, j) = (0, 0)
		while i < len(t) and j < len(S):
			if t[i] == S[j]:
				i += 1
				j += 1
			else:
				j += 1
		if i == len(t):
			return True
		else:
			return False


class Solution:

	def decode(self, S):
		n = len(S)
		x = 'hello'
		(i, j) = (0, 0)
		while i < n:
			if S[i] == x[j]:
				j += 1
				if j > 4:
					return 1
			i += 1
		return 0


class Solution:

	def decode(self, S):
		a = ['h', 'e', 'l', 'l', 'o']
		s = list(S)
		c = 0
		for i in s:
			if i.islower():
				if i == a[0]:
					a.pop(0)
					c = c + 1
			if c == 5:
				return 1
		return 0


class Solution:

	def decode(self, s):
		ans = ''
		i = 0
		target = ['h', 'e', 'l', 'l', 'o']
		for ch in s:
			if i < 5 and ch == target[i]:
				ans += ch
				i += 1
		if ans == 'hello':
			return True
		else:
			return False


class Solution:

	def decode(self, S):
		requiredCode = 'hello'
		helloCharPointer = 0
		for i in range(len(S)):
			currentChar = S[i]
			if currentChar == requiredCode[helloCharPointer]:
				helloCharPointer += 1
				if helloCharPointer >= len(requiredCode):
					return True
		return False


class Solution:

	def decode(self, S):
		target = 'hello'
		start_index = 0
		for i in range(len(S)):
			if S[i] == target[start_index]:
				start_index += 1
			if start_index > 4:
				return True
		return False


class Solution:

	def decode(self, S):
		hello = 'hello'
		ind = 0
		for i in range(len(S)):
			if S[i] == hello[ind]:
				ind += 1
				if ind == len(hello):
					return 'yes'
		return ''


class Solution:

	def decode(self, S):
		st = 'hello'
		p = 0
		for i in range(len(S)):
			if S[i] == st[p]:
				p += 1
			if p == 5:
				return True
		return False


class Solution:

	def decode(self, S):
		h = 'hello '
		m = 0
		for i in S:
			if i == h[m]:
				m += 1
		if m > 4:
			return 1
		return 0


class Solution:

	def decode(self, S):
		x = 'hello'
		cnt = 0
		a = 0
		for i in range(0, len(S)):
			if x[a] == S[i]:
				cnt += 1
				a += 1
			if cnt > 4:
				return True
		else:
			return False


class Solution:

	def decode(self, S):
		data = 'hello'
		(i, j) = (0, 0)
		while i < len(S):
			if S[i] == data[j]:
				j += 1
			i += 1
			if j == 5:
				return True
		return False


class Solution:

	def decode(self, S):
		tgt = 'hello'
		j = 0
		for i in s:
			if j >= 5:
				break
			if i == tgt[j]:
				j += 1
		if j == 5:
			return True
		else:
			return False