In the given range [L, R], print all numbers having unique digits. e.g. In range 10 to 20 should print all numbers except 11.
Example 1:
Input:
L = 10
R = 20
Output:
10 12 13 14 15 16 17 18 19 20
Explanation:
The number 11 has two 1 therefore
11 is not a unique number.
Example 2:
Input:
L = 1
R = 9
Output:
1 2 3 4 5 6 7 8 9
Explanation:
All the Numbers are unique.
Your Task:  
You don't need to read input or print anything. Your task is to complete the function uniqueNumbers() which takes two integers L and R as an input parameter and returns the list/vector of all the unique numbers present between L to R.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= L <= R <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3
class Solution:
	def uniqueNumbers(self, L, R):
		# code here

Solutions:
class Solution:

	def uniqueNumbers(self, L, R):
		return [i for i in range(L, R + 1) if len(str(i)) == len(set(str(i)))]


class Solution:

	def uniqueNumbers(self, L, R):
		an = []
		for i in range(L, R + 1):
			l = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
			t = 1
			k = str(i)
			for j in k:
				l[int(j)] += 1
				if l[int(j)] > 1:
					t = 0
					break
			if t == 1:
				an.append(i)
		return an


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			num = str(i)
			freq = [0] * 10
			flag = 1
			for i in num:
				freq[int(i)] += 1
				if freq[int(i)] == 2:
					flag = 0
					break
			if flag:
				ans.append(int(num))
		return ans


class Solution:

	def unique(self, n):
		h = {}
		for i in str(n):
			if i in h:
				h[i] += 1
			else:
				h[i] = 1
		for i in h:
			if h[i] > 1:
				return False
		return True

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			if self.unique(i) == True:
				ans.append(i)
		return ans


class Solution:

	def uniqueNumbers(self, L, R):
		v = []
		for i in range(L, R + 1):
			res = list(map(int, str(i)))
			k = len(res)
			if len(res) > 1:
				s = set(res)
				if len(s) == k:
					v.append(i)
			else:
				v.append(i)
		return v


class Solution:

	def is_unique(self, num):
		unique = set()
		for j in str(num):
			if j in unique:
				return False
			else:
				unique.add(j)
		return True

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			if self.is_unique(i):
				ans.append(i)
		return ans


class Solution:

	def uniqueNumbers(self, l, r):
		c = []
		for i in range(l, r + 1):
			s = list(str(i))
			unitDigits = set()
			for j in range(len(s)):
				unitDigits.add(s[j])
			if len(s) == len(unitDigits):
				c.append(i)
		return c


class Solution:

	def uniqueNumbers(self, L, R):
		a = []
		for i in range(L, R + 1):
			iStr = str(i)
			flag = 0
			while len(iStr) != 0:
				ele = iStr[0]
				iStr = iStr[1:]
				if ele in iStr:
					flag = 1
					break
			if flag == 0:
				a.append(i)
		return a


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for num in range(L, R + 1):
			dict_ = {}
			result = num
			while num:
				last_digit = num % 10
				if dict_.get(last_digit, 0) > 0:
					break
				dict_[last_digit] = 1
				num = num // 10
			else:
				ans.append(result)
		return ans


class Solution:

	def is_uniqu(self, n):
		n = str(n)
		if len(n) == len(set(n)):
			return True
		return False

	def uniqueNumbers(self, L, R):
		res = []
		for i in range(L, R + 1):
			if self.is_uniqu(i):
				res.append(i)
		return res


class Solution:

	def uniqueNumbers(self, L, R):
		lis = []
		for i in range(L, R + 1):
			str_n = str(i)
			for j in str_n:
				if str_n.count(j) != 1:
					break
				elif j == str_n[-1]:
					lis.append(i)
		return lis


from collections import Counter

class Solution:

	def uniqueNumbers(self, L, R):
		res = []
		for i in range(L, R + 1):
			if len(set(str(i))) == len(str(i)):
				res.append(i)
		return res


class Solution:

	def uniqueNumbers(self, L, R):
		s = []
		d = {i: set(str(i)) for i in range(l, r + 1)}
		for i in d:
			if len(str(i)) == len(d[i]):
				s.append(i)
		s.sort()
		return s


class Solution:

	def uniqueNumbers(self, L, R):
		li = [str(i) for i in range(L, R + 1)]
		n = len(li)
		d = dict.fromkeys(li, set())
		for i in range(n):
			s = set(sorted(li[i]))
			d[li[i]] = s
		ans = []
		for k in d:
			if len(k) == len(d[k]):
				ans.append(int(k))
		ans.sort()
		return ans


class Solution:

	def uniqueNumbers(self, L, R):
		z = []
		for i in range(L, R + 1):
			count = 0
			for j in str(i):
				if str(i).count(j) != 1:
					count = 1
					break
			if count == 0:
				z.append(i)
		return z


class Solution:

	def uniqueNumbers(self, L, R):
		a = []

		def check(s):
			s = str(s)
			j = {}
			for i in s:
				if i in j:
					return False
				else:
					j[i] = 1
			else:
				return True
		for i in range(L, R + 1):
			if check(i):
				a.append(i)
		return a


class Solution:

	def uniqueNumbers(self, L, R):
		repeat = False
		unique_digits = []
		for temp in range(L, R + 1):
			repeat = False
			l = []
			i = temp
			while i > 0:
				rem = i % 10
				if rem not in l:
					l.append(rem)
				else:
					repeat = True
				i = i // 10
			if not repeat:
				unique_digits.append(temp)
		return unique_digits


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for c in range(L, R + 1):
			x = str(c)
			l = len(x)
			if l == len(set(x)):
				ans.append(c)
		return ans


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		s = set()
		j = 0
		for i in range(L, R + 1):
			j = i
			s.clear()
			while j > 0:
				if j % 10 not in s:
					s.add(j % 10)
					j = j // 10
				else:
					j = -1
					break
			if j != -1:
				ans.append(i)
		return ans


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			s = str(i)
			l = len(s)
			if l == len(set(s)):
				ans.append(i)
		return ans


class Solution:

	def uniqueNumbers(self, L, R):
		c = []
		list1 = list(range(L, R + 1))
		for i in range(len(list1)):
			s = str(list1[i])
			l = set(s)
			if len(s) == len(l):
				c.append(list1[i])
		return c


class Solution:

	def uniqueNumbers(self, L, R):
		lst = []
		for num in range(L, R + 1):
			if len(set(str(num))) == len(str(num)):
				num = int(num)
				lst.append(num)
		return lst


class Solution:

	def uniqueNumbers(self, L, R):
		lst = []
		for i in range(L, R + 1):
			check = False
			num = i
			vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
			while num > 0:
				bab = num % 10
				if vis[bab] == 1:
					check = True
					break
				else:
					vis[bab] = 1
				num = int(num / 10)
			if check == False:
				lst.append(i)
		return lst


class Solution:

	def uniqueNumbers(self, L, R):
		a = []
		for i in range(L, R + 1):
			if len(str(i)) == 1:
				a.append(i)
			else:
				b = str(i)
				s = ''
				for j in b:
					if j in s:
						break
					else:
						s += j
				if len(s) == len(b):
					a.append(i)
		return a


class Solution:

	def isNot(self, num):
		hm = {}
		while num > 0:
			rem = num % 10
			if rem not in hm:
				hm[rem] = 1
			else:
				hm[rem] += 1
			num = num // 10
		for i in hm.keys():
			if hm[i] > 1:
				return True

	def uniqueNumbers(self, L, R):
		l1 = []
		for i in range(L, R + 1):
			if not self.isNot(i):
				l1.append(i)
		return l1


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			s = set()
			temp = i
			flag = True
			while temp != 0:
				rem = temp % 10
				if rem in s:
					flag = False
					break
				s.add(rem)
				temp = temp // 10
			if flag:
				ans.append(i)
		return ans


from collections import Counter

class Solution:

	def uniqueNumbers(self, L, R):
		u = []
		for j in range(L, R + 1):
			x = str(j)
			s = Counter(x)
			v = 0
			for r in s:
				if s[r] == 1:
					v += 1
			if v == len(x):
				u.append(int(x))
		return u


class Solution:

	def uniqueNumbers(self, L, R):
		d = {}
		for i in range(L, R + 1):
			b = tuple(str(i))
			if len(set(b)) == len(b):
				d[i] = 1
		b = list(d.keys())
		b.sort()
		return b


class Solution:

	def uniqueNumbers(self, L, R):
		new = []
		for i in range(L, R + 1):
			a = str(i)
			res = ''
			for x in a:
				b = a.count(x)
				if b > 1:
					continue
				elif b == 1:
					res += x
			if len(res) == len(a):
				new.append(res)
		return new


class Solution:

	def uniqueNumbers(self, L, R):
		u = []
		for i in range(L, R + 1):
			x = list(str(i))
			a = len(x)
			b = len(set(x))
			if a == b:
				u.append(i)
		return u


class Solution:

	def uniqueNumbers(self, L, R):
		a = []
		for i in range(L, R + 1):
			k = list(str(i))
			uniquedigit = set()
			for j in range(len(k)):
				uniquedigit.add(k[j])
			if len(uniquedigit) == len(k):
				a.append(i)
		return a


class Solution:

	def uniqueNumbers(self, L, R):
		arr = []
		for i in range(L, R + 1):
			b = str(i)
			flag = 0
			for z in b:
				if b.count(z) > 1:
					flag = 1
			if flag == 0:
				arr.append(b)
		return arr


class Solution:

	def uniqueNumbers(self, L, R):
		c = []
		for i in range(L, R + 1):
			if not self.Not(i):
				c.append(i)
		return c

	def Not(self, n):
		d = {}
		while n > 0:
			rem = n % 10
			if rem not in d:
				d[rem] = 1
			else:
				d[rem] += 1
			n = n // 10
		for i in d.keys():
			if d[i] > 1:
				return True


class Solution:

	def ck(self, n):
		h = {}
		rem = 0
		while n:
			rem = n % 10
			h[rem] = 1 + h.get(rem, 0)
			n = n // 10
		for i in h:
			if h[i] > 1:
				return False
		return True

	def uniqueNumbers(self, L, R):
		l = []
		for i in range(L, R + 1):
			if self.ck(i):
				l.append(i)
		return l


class Solution:

	def uniqueNumbers(self, L, R):
		li = []
		for i in range(L, R + 1):
			if len(set(str(i))) != len(str(i)):
				continue
			else:
				li.append(i)
		return li


class Solution:

	def uniqueNumbers(self, L, R):
		li = []
		for i in range(L, R + 1):
			flag = True
			d = dict()
			for j in range(len(str(i))):
				d[str(i)[j]] = d.get(str(i)[j], 0) + 1
			for (k, v) in d.items():
				if v > 1:
					flag = False
			if flag:
				li.append(i)
		return li


class Solution:

	def uniqueNumbers(self, L, R):
		l1 = []
		for i in range(L, R + 1):
			s = str(i)
			n = len(s)
			l = list(s)
			s1 = set(l)
			if len(s1) == n:
				l1.append(i)
		return l1


class Solution:

	def uniqueNumbers(self, L, R):

		def unique_digits(n: int) -> bool:
			return set(str(n)).__len__() == str(n).__len__()
		return [x for x in range(L, R + 1) if unique_digits(x)]


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			i = list(str(i))
			if len(set(i)) != len(i):
				continue
			else:
				ans.append(int(''.join(i)))
		return ans


class Solution:

	def uniqueNumbers(self, L, R):
		res = []
		for i in range(L, R + 1):
			isRepeated = False
			char = str(i)
			dict = {}
			for j in char:
				if j in dict:
					isRepeated = True
					break
				else:
					dict[j] = 1
			if not isRepeated:
				res.append(i)
		return res


class Solution:

	def uniqueNumbers(self, L, R):
		res = []
		for i in range(L, R + 1):
			s = list(str(i))
			s1 = set()
			for j in range(len(s)):
				s1.add(s[j])
			if len(s) == len(s1):
				res.append(i)
		return res


class Solution:

	def isunique(self, x):
		d = {}
		while x != 0:
			if x % 10 in d:
				return False
			d[x % 10] = 1
			x //= 10
		return True

	def uniqueNumbers(self, L, R):
		l = []
		for i in range(L, R + 1):
			if self.isunique(i):
				l.append(i)
		return l


import math

class Solution:

	def uniqueNumbers(self, L, R):
		l = []
		for i in range(L, R + 1):
			if len(set(str(i))) != len(str(i)):
				continue
			else:
				l.append(i)
		return l


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			s = i
			d = {}
			flag = 0
			while s:
				if s % 10 not in d:
					d[s % 10] = 1
					s = s // 10
				else:
					flag = 1
					break
			if flag == 0:
				ans.append(i)
		return ans


class Solution:

	def isNot(self, num):
		d = {}
		a = str(num)
		for i in a:
			if i not in d:
				d[i] = 1
			else:
				d[i] += 1
		for (i, j) in d.items():
			if j > 1:
				return False
		return True

	def uniqueNumbers(self, L, R):
		res = []
		for i in range(L, R + 1, 1):
			if Solution().isNot(i):
				res.append(i)
		return res


class Solution:

	def uniqueNumbers(self, L, R):
		l = []
		for i in range(L, R + 1):
			s = list(str(i))
			unitDigits = set()
			for j in range(len(s)):
				unitDigits.add(s[j])
			if len(s) == len(unitDigits):
				l.append(i)
		return l


class Solution:

	def uniqueNumbers(self, l, r):
		a = []
		for i in range(l, r + 1):
			a.append(str(i))
		b = []
		for i in a:
			if len(list(i)) == len(list(set(i))):
				b.append(i)
		return b


class Solution:

	def mod(self, n):
		l = []
		while n > 0:
			z = n % 10
			if z not in l:
				l.append(z)
				n = n // 10
			else:
				return 0
		return 1

	def uniqueNumbers(self, L, R):
		c = []
		for x in range(L, R + 1):
			if self.mod(x) == 1:
				c.append(x)
		return c


class Solution:

	def uniqueNumbers(self, L, R):
		res = []
		for i in range(L, R + 1):
			temp = str(i)
			string = set(temp)
			if len(temp) == len(string):
				res.append(i)
		return res


class Solution:

	def uniqueNumbers(self, L, R):
		l = []
		for i in range(L, R + 1):
			s = set()
			for j in str(i):
				if j in s:
					break
				else:
					s.add(j)
			else:
				l.append(i)
		return l


class Solution:

	def uniqueNumbers(self, L, R):
		arr = []
		for d in range(L, R + 1):
			ls = list(str(d))
			st = set(ls)
			if len(ls) == len(st):
				arr.append(d)
		return arr


class Solution:

	def uniqueNumbers(self, L, R):
		list1 = []
		for i in range(l, r + 1):
			s = list(str(i))
			unitDigits = set()
			for j in range(len(s)):
				unitDigits.add(s[j])
			if len(s) == len(unitDigits):
				list1.append(i)
		return list1
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		ob = Solution()
		ans = ob.uniqueNumbers(l, r)
		for a in ans:
			print(a, end=' ')
		print()


class Solution:

	def uniqueNumbers(self, L, R):
		d = {}
		lst = []
		for i in range(L, R + 1):
			vari = [int(x) for x in str(i)]
			flag = set(vari)
			if len(vari) > len(flag):
				pass
			else:
				lst.append(i)
		return lst
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		ob = Solution()
		ans = ob.uniqueNumbers(l, r)
		for a in ans:
			print(a, end=' ')
		print()


class Solution:

	def uniqueNumbers(self, L, R):
		l = [str(x) for x in range(L, R + 1)]
		ans = []
		for x in l:
			if len(x) == len(set(x)):
				ans.append(int(x))
		return ans
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		ob = Solution()
		ans = ob.uniqueNumbers(l, r)
		for a in ans:
			print(a, end=' ')
		print()


class Solution:

	def uniqueNumbers(self, L, R):
		l = []
		for i in range(L, R + 1):
			s = {}
			d = str(i)
			f = 0
			for j in d:
				if j in s:
					f = 1
					break
				else:
					s[j] = 1
			if f == 0:
				l.append(i)
		return l
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		ob = Solution()
		ans = ob.uniqueNumbers(l, r)
		for a in ans:
			print(a, end=' ')
		print()


class Solution:

	def uniqueNumbers(self, L, R):
		arr = []
		for i in range(L, R + 1):
			b = str(i)
			flag = 0
			for z in b:
				if b.count(z) > 1:
					flag = 1
			if flag == 0:
				arr.append(b)
		return arr
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		ob = Solution()
		ans = ob.uniqueNumbers(l, r)
		for a in ans:
			print(a, end=' ')
		print()


class Solution:

	def uniqueNumbers(self, L, R):
		res = []
		while L <= R:
			m = {}
			flag = True
			l = L
			while l:
				x = l % 10
				if x in m:
					flag = False
					break
				else:
					m[x] = 1
				l = l // 10
			if flag == True:
				res.append(L)
			L += 1
		return res
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(l, r) = input().split()
		(l, r) = (int(l), int(r))
		ob = Solution()
		ans = ob.uniqueNumbers(l, r)
		for a in ans:
			print(a, end=' ')
		print()


class Solution:

	def uniqueNumbers(self, L, R):
		ans = []
		for i in range(L, R + 1):
			num = i
			visited = [0 for i in range(10)]
			while num:
				if visited[int(num % 10)] != 0:
					break
				visited[int(num % 10)] = 1
				num = int(num / 10)
			if num == 0:
				ans.append(i)
		return ans