Given a string S and another string patt. Find the character in patt that is present at the minimum index in S.
 
Example 1:
Input: S = "zsyle", patt = "bjz"
Output: "z"
Example 2:
Input: S = "anskg", patt = "me"
Output: "$"
 
Your Task:
You don't need to read or print anything. Your task is to complete the function printMinIndexChar() which takes S and patt as input parameter and returns the character in patt that is present at the minimum index in S. If not possible returns "$".
 
Expected Time Complexity: O(max(|str|, |patt|))
Expected Auxilary Space: O(K) where K <= 26
 
Constraints:
1 ≤ |S|, |patt| ≤ 10^{4}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity:  O(max(|str|, |patt|))
Expected Auxiliary Space: O(K) where K <= 26

Starter code:
class Solution:
    def printMinIndexChar(self, S, patt):
		#Code here

Solutions:
class Solution:

	def printMinIndexChar(self, s, patt):
		for i in s:
			if i in patt:
				return i
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		chars = set((char for char in patt))
		for (idx, char) in enumerate(S):
			if char in chars:
				return char
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		d = dict()
		for i in patt:
			if i in S:
				d.update({i: S.index(i)})
		if len(d) == 0:
			return '$'
		min = 99999999
		mc = '#'
		for i in d.keys():
			if d[i] < min:
				min = d[i]
				mc = i
		return mc


class Solution:

	def printMinIndexChar(self, S, patt):
		for i in S:
			if i in patt:
				return i
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		patt_set = set(list(patt))
		for let in S:
			if let in patt_set:
				return let
		return '$'


class Solution:

	def printMinIndexChar(self, s, patt):
		lst = []
		for i in range(len(patt)):
			for j in range(len(s)):
				if s[j] == patt[i]:
					lst.append(j)
					break
		if len(lst) == 0:
			return '$'
		else:
			lst.sort()
			return s[lst[0]]


class Solution:

	def printMinIndexChar(self, s, patt):
		dic = {}
		for i in range(len(s)):
			if dic.get(s[i]) == None:
				dic[s[i]] = i
		nini = len(s)
		k = ''
		for i in patt:
			if dic.get(i) != None and dic[i] < nini:
				k = i
				nini = dic[i]
		if k != '':
			return k
		else:
			return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		maap = {}
		for i in range(len(S)):
			if S[i] in maap:
				pass
			else:
				maap[S[i]] = i
		flag = False
		min_val = float('inf')
		for i in range(len(patt)):
			if patt[i] in maap:
				j = maap[patt[i]]
				if j < min_val:
					min_val = j
					flag = True
		if flag:
			return S[min_val]
		else:
			return '$'


class Solution:

	def printMinIndexChar(self, l, p):
		s = []
		for i in range(len(l)):
			if l[i] in p:
				s.append(i)
		if len(s) == 0:
			return '$'
		else:
			return l[min(s)]


class Solution:

	def printMinIndexChar(self, S, patt):
		patt = set(patt)
		for i in range(len(S)):
			if S[i] in patt:
				return S[i]
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		a = []
		for i in patt:
			if i in S:
				a.append(S.index(i))
		if len(a) == 0:
			return '$'
		return S[min(a)]


class Solution:

	def printMinIndexChar(self, S, patt):
		min_index = 9999999999
		min_val = None
		dict = {}
		for i in patt:
			if i in S:
				index = S.index(i)
				if index < min_index:
					min_index = index
					min_value = i
		if min_index == 9999999999:
			return '$'
		return min_value


class Solution:

	def printMinIndexChar(self, S, patt):
		dic = {}
		for j in patt:
			dic[j] = 1
		for i in S:
			if i in dic:
				return i
		return '$'


class Solution:

	def printMinIndexChar(self, s, patt):
		hashmap = {}
		d = {}
		for i in range(len(s)):
			if s[i] not in hashmap:
				hashmap[s[i]] = i
		for (i, j) in hashmap.items():
			if i in patt:
				d[i] = j
		if d:
			a = min(d.values())
		for (i, j) in d.items():
			if j == a:
				return i
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		hash_map = {}
		n = len(patt)
		for i in range(n):
			if patt[i] in hash_map:
				continue
			else:
				hash_map[patt[i]] = 1
		for i in range(len(S)):
			if S[i] in hash_map:
				return S[i]
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		max = len(S)
		c = ''
		for i in patt:
			if i in S:
				if max > S.index(i):
					max = S.index(i)
					c = i
		if len(c) == 0:
			return '$'
		return c


class Solution:

	def printMinIndexChar(self, S, patt):
		p = []
		for i in patt:
			if i in S:
				p.append(S.index(i))
		if len(p) != 0:
			q = min(p)
			return S[q]
		else:
			return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		id = 999
		for i in patt:
			if i in S:
				id = min(id, S.index(i))
		if id == 999:
			return '$'
		else:
			return S[id]


class Solution:

	def printMinIndexChar(self, S, patt):
		c = []
		for i in S:
			if i in patt:
				c.append(S.index(i))
		if len(c) >= 1:
			return S[min(c)]
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		x = list(S)
		l = []
		for i in patt:
			if i in x:
				l.append(x.index(i))
		if len(l) == 0:
			return '$'
		return S[min(l)]


class Solution:

	def printMinIndexChar(self, S, patt):
		S = list(str(S))
		p = list(str(patt))
		l = []
		flag = 0
		for i in range(0, len(p)):
			for j in range(0, len(S)):
				if p[i] == S[j]:
					l.append(j)
					flag = 1
		return S[min(l)] if flag == 1 else '$'


class Solution:

	def printMinIndexChar(self, s, patt):
		l = ''
		for i in range(len(s)):
			if s[i] in patt:
				return s[i]
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		l = []
		for i in range(len(S)):
			if S[i] in patt:
				l += [i]
		if len(l) != 0:
			return S[min(l)]
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		d = {}
		for i in range(len(S)):
			if S[i] not in d.keys():
				d[S[i]] = i
		mn = int(10000.0)
		found = False
		for i in patt:
			if i in d.keys() and d[i] < mn:
				mn = d[i]
				found = True
				res = i
		return res if found else '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		first_char = ''
		for char in S:
			if char in patt:
				first_char = char
				break
		if first_char:
			return first_char
		else:
			return '$'


class Solution:

	def printMinIndexChar(self, s, patt):
		patSet = set(patt)
		for c in s:
			if c in patSet:
				return c
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		count = [-1] * 26
		for i in range(len(S)):
			if count[ord(S[i]) - ord('a')] == -1:
				count[ord(S[i]) - ord('a')] = i
		res = 10 ** 9
		for i in patt:
			if count[ord(i) - ord('a')] > -1:
				res = min(res, count[ord(i) - ord('a')])
		return S[res] if res < 10 ** 9 else '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		d = dict()
		for i in patt:
			if i in S:
				d[i] = S.index(i)
		if not d:
			return '$'
		else:
			minv = min(d.values())
			for i in d:
				if d[i] == minv:
					return i


class Solution:

	def printMinIndexChar(self, S, patt):
		m = len(S)
		p = ''
		for i in patt:
			if i in S and S.index(i) < m:
				m = S.index(i)
				p = i
		if p == '':
			return '$'
		return p


class Solution:

	def printMinIndexChar(self, S, patt):
		a = [i for i in S]
		b = [i for i in patt]
		for i in range(len(a)):
			if a[i] in b:
				return a[i]
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		ans = [S.index(i) for i in patt if i in S]
		return S[min(ans)] if len(ans) > 0 else '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		for alphabet in S:
			if alphabet in patt:
				return alphabet
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		dict = {}
		for x in range(len(patt)):
			for y in range(len(S)):
				if patt[x] == S[y] and patt[x] not in dict:
					dict[patt[x]] = y
		if len(dict) == 0:
			return '$'
		mini = min(dict.values())
		for key in dict:
			if dict[key] == mini:
				return key
		return '$'


class Solution:

	def printMinIndexChar(self, s, p):
		for i in range(len(s)):
			if s[i] in p:
				return s[i]
			else:
				pass
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		d = {}
		for i in range(len(patt)):
			if patt[i] in d:
				continue
			else:
				d[patt[i]] = i
		for c in S:
			if c in d:
				return c
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		l = []
		for i in patt:
			if i in S:
				x = S.find(i)
				l.append(x)
		if len(l) == 0:
			return '$'
		else:
			a = min(l)
			return S[a]


class Solution:

	def printMinIndexChar(self, S, patt):
		hash = [0 for i in range(26)]
		for i in patt:
			hash[ord(i) - 97] = +1
		for i in S:
			if hash[ord(i) - 97]:
				return '' + i
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		for x in S:
			if x in patt:
				return x
				break
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		d = {}
		for i in patt:
			try:
				d[S.index(i)] = i
			except:
				pass
		if d:
			d1 = sorted(d.keys())
			return S[d1[0]]
		else:
			return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		d = {}
		for i in patt:
			if i in S:
				d[i] = S.index(i)
		if len(d) > 0:
			x = min(d.values())
			for i in d:
				if d[i] == x:
					return i
		return '$'


class Solution:

	def printMinIndexChar(self, S, patt):
		l = []
		for i in range(len(S)):
			l.append(S[i])
		m = []
		for i in range(len(patt)):
			m.append(patt[i])
		res = []
		for i in l:
			if i in m:
				res.append(i)
		if len(res) == 0:
			return '$'
		else:
			return res[0]


class Solution:

	def printMinIndexChar(self, S, patt):
		A = []
		for k in S:
			if k in patt:
				A.append(k)
		if len(A) == 0:
			return '$'
		else:
			return A[0]


class Solution:

	def printMinIndexChar(self, S, patt):
		Str = S
		pat = patt
		dict = []
		if len(set(Str) & set(pat)) == 0:
			return '$'
		for i in pat:
			if i in Str:
				dict.append(Str.index(i))
		return Str[min(dict)]


class Solution:

	def printMinIndexChar(self, S, patt):
		v = []
		for i in range(len(S)):
			if S[i] in patt:
				v.append(i)
		if len(v) == 0:
			return '$'
		return S[min(v, default=0)]


class Solution:

	def printMinIndexChar(self, S, patt):
		index = float('inf')
		d = {}
		for (i, c) in enumerate(S):
			if c not in d:
				d[c] = i
		for c in patt:
			index = min(index, d.get(c, float('inf')))
		return '$' if index == float('inf') else S[index]


class Solution:

	def printMinIndexChar(self, S, patt):
		list = []
		for i in patt:
			if i in S:
				list.append(S.index(i))
		if len(list) == 0:
			return '$'
		else:
			final = min(list)
			return S[final]


class Solution:

	def printMinIndexChar(self, s, patt):
		d = dict()
		min = len(s)
		k = '$'
		for i in range(0, len(patt)):
			if patt[i] in s:
				d[patt[i]] = s.index(patt[i])
			else:
				continue
		for i in d.keys():
			if d[i] < min:
				min = d[i]
				k = i
			else:
				continue
		return k


class Solution:

	def printMinIndexChar(self, S, patt):
		for c in S:
			if c in patt:
				return c
		return '$'


class Solution:

	def printMinIndexChar(self, s, patt):
		l = []
		for i in s:
			if i in patt:
				l.append(i)
		if l == []:
			return '$'
		return l[0]


class Solution:

	def printMinIndexChar(self, S, patt):
		index = {}
		j = 0
		for i in S:
			if i not in index:
				index[i] = j
				j += 1
			else:
				j += 1
		m = -1
		for i in patt:
			if i in index:
				if m == -1:
					m = index[i]
				elif m > index[i]:
					m = index[i]
		if m == -1:
			return '$'
		else:
			return S[m]