Given an array arr[] of n numbers. The task is to print only those numbers whose digits are from set {1,2,3}.
Example 1:
Input:
n = 3
arr[] = {4,6,7}
Output: -1
Explanation: No elements are there in the 
array which contains digits 1, 2 or 3.
Example 2:
Input:
n = 4
arr[] = {1,2,3,4}
Output: 1 2 3
Explanation: 1, 2 and 3 are the only 
elements in the array which conatins 
digits as 1, 2 or 3.
Your Task:
Complete findAll function and marked satisfied number as '1' in the map mp in range 1 to 1000000. If no number is marked as satified number -1 will automatically be printed by the drivers code. The driver code prints the elements in sorted order.
Expected Time Complexity : O(n)
Expected Auxilliary Space : O(n)
Constraints:
1 <= n <= 10^{6}
1 <= A[i] <= 10^{6}

Difficulty: EASY
Tags: String algorithms

Data structures

Mathematics
Skill types: Data structures
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)

Starter code:
#User function Template for python3

#Function to find all the numbers with only 1,2 and 3 in their digits.
def findAll():
    #code here

Solutions:
def findAll():
	global mp
	s = {'1', '2', '3'}
	for i in range(1, 1000001):
		st = set(str(i))
		if len(st.difference(s)) == 0:
			mp[i] = 1


def findAll():
	r = {'1', '2', '3'}
	for i in range(1, 1000001):
		s = set(str(i))
		if s.issubset(r):
			mp[i] = 1


def findAll():
	mp[1] = mp[2] = mp[3] = 1
	for i in range(11, 1000001):
		k = str(i)
		if ('1' in k or '2' in k or '3' in k) and '4' not in k and ('5' not in k) and ('6' not in k) and ('7' not in k) and ('8' not in k) and ('9' not in k) and ('0' not in k):
			mp[i] = 1


def valid(n):
	while n:
		d = n % 10
		if d == 0 or d >= 4:
			return False
		n //= 10
	return True

def findAll():
	for el in range(1, int(1000000.0) + 1):
		if valid(el):
			mp[el] = 1


def findAll():
	l = [['1'], ['1', '2'], ['1', '2', '3'], ['2'], ['2', '3'], ['3'], ['1', '3']]
	for i in range(1, 10 ** 6 + 1):
		s = list(set(str(i)))
		if len(s) <= 3:
			s.sort()
			if s in l:
				mp[i] = 1


def findAll():
	for i in range(1, 1000000):
		if valid(i):
			mp[i] = 1

def valid(ind):
	while ind > 1:
		key = ind % 10
		if key < 1 or key > 3:
			return False
		ind //= 10
	return True


def findAll():
	num = 1
	j = 1
	a = [1, 2, 3]
	mp[1] = 1
	mp[2] = 1
	mp[3] = 1
	j = 0
	while num <= 1000000:
		num2 = a[j]
		j += 1
		if num2 * 10 + 1 <= 1000000:
			a.append(num2 * 10 + 1)
			mp[num2 * 10 + 1] = 1
		if num2 * 10 + 2 <= 1000000:
			a.append(num2 * 10 + 2)
			mp[num2 * 10 + 2] = 1
		if num2 * 10 + 3 <= 1000000:
			a.append(num2 * 10 + 3)
			mp[num2 * 10 + 3] = 1
		num = num2 * 10 + 3


def findAll():
	xset = {'1', '2', '3'}
	for i in range(1, 1000000):
		s = set(str(i))
		if s.issubset(xset):
			mp[i] = 1


def isValid(num):
	while num:
		rem = num % 10
		if rem in (4, 5, 6, 7, 8, 9, 0):
			return False
		num //= 10
	return True

def findAll():
	for i in range(1, 10 ** 6 + 1):
		if isValid(i):
			mp[i] = 1


def fall(n, i, s):
	global mp
	if i > n:
		return
	mp[int(s)] = True
	fall(n, i + 1, s + '1')
	fall(n, i + 1, s + '2')
	fall(n, i + 1, s + '3')

def findAll():
	fall(7, 1, '1')
	fall(7, 1, '2')
	fall(7, 1, '3')


def findAll():
	for i in range(1, 1000000):
		if ('1' in str(i) or '2' in str(i) or '3' in str(i)) and len(str(i)) == 1:
			mp[i] = i
		if '0' not in str(i) and '4' not in str(i) and ('5' not in str(i)) and ('6' not in str(i)) and ('7' not in str(i)) and ('8' not in str(i)) and ('9' not in str(i)):
			mp[i] = i


def findAll():
	s = {'1', '2', '3'}
	for i in range(1, 1000000 + 1):
		for j in str(i):
			if j not in s:
				break
		else:
			mp[i] = 1


def isV(n):
	while n != 0:
		r = n % 10
		if r not in [2, 3, 1]:
			return False
		n //= 10
	return True

def findAll():
	for i in range(1, 10 ** 6 + 1):
		if isV(i):
			mp[i] = 1


def isv(rem):
	no = 0
	while rem != 0:
		num = rem % 10
		if num != 1 and num != 2 and (num != 3):
			return False
		rem //= 10
	return True

def findAll():
	cnt = 0
	for i in range(1, 10 ** 6 + 1):
		if isv(i):
			mp[i] = 1


def isValid(num):
	while num != 0:
		rem = num % 10
		if rem != 1 and rem != 2 and (rem != 3):
			return False
		num //= 10
	return True

def findAll():
	for i in range(1, 1000001):
		if isValid(i) == True:
			mp[i] = 1


def findAll():
	for x in range(1, 1000000):
		if str(x).replace('1', '').replace('2', '').replace('3', '') == '':
			mp[x] = 1


def findAll():
	for i in range(1, 10 ** 6 + 1):
		if satisfies(i):
			mp[i] = 1

def satisfies(n):
	while n > 0:
		x = n % 10
		if x not in [1, 2, 3]:
			return False
		n = n // 10
	return True


def findAll():
	for i in [1, 2, 3]:
		mp[i] = 1
	for i in [1, 2, 3]:
		for j in [1, 2, 3]:
			mp[10 * i + j] = 1
	for i in [1, 2, 3]:
		for j in [1, 2, 3]:
			for k in [1, 2, 3]:
				mp[100 * i + 10 * j + k] = 1
	for i in [1, 2, 3]:
		for j in [1, 2, 3]:
			for k in [1, 2, 3]:
				for l in [1, 2, 3]:
					mp[1000 * i + 100 * j + 10 * k + l] = 1
	for i in [1, 2, 3]:
		for j in [1, 2, 3]:
			for k in [1, 2, 3]:
				for l in [1, 2, 3]:
					for m in [1, 2, 3]:
						mp[10000 * i + 1000 * j + 100 * k + 10 * l + m] = 1
	for i in [1, 2, 3]:
		for j in [1, 2, 3]:
			for k in [1, 2, 3]:
				for l in [1, 2, 3]:
					for m in [1, 2, 3]:
						for n in [1, 2, 3]:
							mp[100000 * i + 10000 * j + 1000 * k + 100 * l + 10 * m + n] = 1


def check(n):
	while n > 0:
		d = n % 10
		if d not in [1, 2, 3]:
			return 0
		n = n // 10
	return 1

def findAll():
	for i in range(1, 1000001):
		if check(i):
			mp[i] = 1


def findAll():
	for i in range(1, 1000001):
		a = str(i)
		f = 0
		for j in range(4, 10):
			if str(j) in a:
				f = 1
				break
		if f == 0 and '0' not in a:
			mp[i] = 1


def findAll():
	list1 = []
	for i in range(1, 1000000):
		j = i
		s = 1
		while j > 0:
			res = j % 10
			if res != 1 and res != 2 and (res != 3):
				s = 0
				break
			j = j // 10
		if s == 1:
			mp[i] = 1
	return mp


def findAll():

	def contains(num):
		while num > 0:
			d = num % 10
			if d != 1 and d != 2 and (d != 3):
				return False
			num = num // 10
		return True
	for i in range(1, 1000000 + 1):
		if contains(i):
			mp[i] = 1


def findAll():
	for i in range(1, 1000001):
		if finddigits(i) == True:
			mp[i] = 1

def finddigits(num):
	while num != 0:
		digit = num % 10
		if digit != 1 and digit != 2 and (digit != 3):
			return False
		num = num // 10
	return True


def helper(n):
	if n == 1 or n == 2 or n == 3:
		return True
	while n > 0:
		rem = n % 10
		if rem != 1 and rem != 2 and (rem != 3):
			return False
		n //= 10
	return True

def findAll():
	for i in range(1, 1000001):
		if helper(i):
			mp[i] = 1


def helper(n):
	if n == 1 or n == 2 or n == 3:
		return True
	else:
		n = str(n)
		for i in n:
			if i != '1' and i != '2' and (i != '3'):
				return False
	return True

def findAll():
	for i in range(1, 1000001):
		if helper(i):
			mp[i] = 1


def does_contain(num):
	while num > 0:
		digit = num % 10
		if not (digit >= 1 and digit <= 3):
			return False
		num = num // 10
	return True

def findAll():
	for i in range(1, 10 ** 6 + 1):
		if does_contain(i):
			mp[i] = 1


def findAll():
	j = 1
	while j < 1000000:
		str1 = str(j)
		count = 1
		for i in str1:
			if not (i == '1' or i == '2' or i == '3'):
				count = 0
				break
		if count == 1:
			mp[j] = 1
		j += 1
	return mp


def findAll():
	for i in range(0, 1000001):
		s = str(i)
		l = list(s)
		if '4' not in l and '5' not in l and ('6' not in l) and ('7' not in l) and ('8' not in l) and ('0' not in l) and ('9' not in l):
			mp[i] = 1


def findAll():
	for x in range(1, 1000000):
		if x == 1 or x == 2 or x == 3:
			mp[x] = 1
		elif x > 10:
			n = x
			flag = 0
			while n > 0:
				if n % 10 == 1 or n % 10 == 2 or n % 10 == 3:
					n = n // 10
				else:
					flag = 1
					break
			if flag != 1:
				mp[x] = 1


def findAll():
	for i in range(0, 1000000):
		if isSatisfy(i):
			mp[i] = 1

def isSatisfy(n):
	while n:
		if n % 10 != 1 and n % 10 != 2 and (n % 10 != 3):
			return False
		n = n // 10
	return True


def findAll():

	def cont(i):
		t = i
		while t:
			if t % 10 != 1 and t % 10 != 2 and (t % 10 != 3):
				return False
			t //= 10
		return True
	for i in range(1, 1000000):
		if cont(i):
			mp[i] = 1


def is_contained_required_digits(num, required_digits):
	num = str(num)
	for digit in num:
		if digit not in required_digits:
			return False
	return True

def findAll():
	required_digits = set(['1', '2', '3'])
	for num in range(1, 1000001):
		if is_contained_required_digits(num, required_digits):
			mp[num] = 1


def findAll():
	for i in range(1, 1000001):
		num = i
		flag = 1
		while num > 0:
			dig = num % 10
			if dig not in [1, 2, 3]:
				flag = 0
				break
			num = num // 10
		if flag == 1:
			mp[i] = 1


def findAll():
	digits = {'1', '2', '3'}
	for n in range(1, 1000000):
		valid_digits = True
		for digit in str(n):
			if digit not in digits:
				valid_digits = False
		if valid_digits:
			mp[n] = True


def findAll():
	lis = [1, 2, 3]
	for i in range(1, 1000001):
		val = i
		while val != 0:
			if val % 10 in lis:
				val = val // 10
			else:
				break
			if val == 0:
				mp[i] = 1


def findAll():
	s1 = set(str(123))
	for i in range(1, 1000001):
		s2 = set(str(i))
		if s2.issubset(s1):
			mp[i] = 1


def findAll():
	for i in range(1, 10 ** 6 + 1):
		j = i
		fl = True
		while j:
			rem = j % 10
			if rem not in [1, 2, 3]:
				fl = False
				break
			j = j // 10
		if fl:
			mp[i] = 1


def findAll():
	r = {'1', '2', '3'}
	m = 10 ** 6 + 1
	for i in range(1, m):
		s = set(str(i))
		if s.issubset(r):
			mp[i] = 1


def findAll():
	t = {'1', '2', '3'}
	for i in range(1, 1000001):
		s1 = set(str(i))
		if s1.issubset(t):
			mp[i] = 10