Given an array arr of size n. Print all the numbers less than k and should be such that the difference between every adjacent digit should be 1 in the array.
Note: Return empty list if no such number present, driver code will automatically print -1.
Example 1:
Input:
n = 8, k = 54
arr[] = {7, 98, 56, 43, 45, 23, 12, 8}
Output: 43 45 23 12
Explanation: 43 45 23 12 all these numbers have adjacent 
digits diff as 1 and they areless than 54.
Example 2:
Input:
n = 10, k = 1000
arr[] = {87, 89, 45, 235, 465, 765, 123, 987, 499, 655}
Output: 87 89 45 765 123 987
Explanation: 87 89 45 765 123 987 all these numbers have adjacent
digits diff as 1 and they areless than 1000.
Your Task:
You don't need to read input or print anything. Your task is to complete the function getDigitDiff1AndLessK() which takes the array of integers arr, n and k as parameters and returns a list of integer denoting the answer.
Expected Time Complexity:O(n)
Expected Auxiliary Space:O(1)
Constraints:
1 <= n <= 10^{7}
1 <= k, arr[i] <= 10^{18}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3







class Solution:

    def getDigitDiff1AndLessK(self, arr, n, k):

        # code here

Solutions:
class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		nums = [num for num in arr if num < k and num > 9]
		for num in nums:
			l = list(map(int, str(num)))
			for i in range(len(l) - 1):
				if abs(l[i] - l[i + 1]) != 1:
					break
				elif i == len(l) - 2:
					ans.append(num)
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in range(n):
			if arr[i] < k and arr[i] > 9:
				temp = []
				num = arr[i]
				while num:
					temp.append(num % 10)
					num = num // 10
				flag = True
				for j in range(1, len(temp)):
					if abs(temp[j] - temp[j - 1]) != 1:
						flag = False
						break
				if flag == True:
					ans.append(arr[i])
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		arr1 = []
		for i in arr:
			if i < k and i > 9:
				count = 0
				x = str(i)
				for j in range(len(x) - 1):
					if int(x[j]) - int(x[j + 1]) == 1 or int(x[j + 1]) - int(x[j]) == 1:
						count += 1
				if count == len(x) - 1:
					arr1.append(i)
		return arr1


class Solution:

	def is_adj_diff(self, num):
		num = str(num)
		flag = False
		for i in range(len(num) - 1):
			if abs(int(num[i]) - int(num[i + 1])) == 1:
				flag = True
			else:
				return False
		return flag

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in arr:
			if i < k:
				check = self.is_adj_diff(i)
				if check:
					ans.append(i)
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		res = []
		for i in arr:
			temp = False
			l = len(str(i))
			if i < k and l > 1:
				i = str(i)
				for j in range(1, l):
					if abs(int(i[j - 1]) - int(i[j])) != 1:
						temp = False
						break
					else:
						temp = True
			if temp:
				res.append(i)
		return res


class Solution:

	def diff1(self, num):
		s = str(num)
		m = len(s)
		if m == 1:
			return False
		for i in range(m - 1):
			if abs(int(s[i]) - int(s[i + 1])) == 1:
				continue
			return False
		return True

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in range(n):
			if arr[i] < k and self.diff1(arr[i]):
				ans.append(arr[i])
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		t = 0
		for i in arr:
			e = str(i)
			for i in range(1, len(e)):
				if abs(int(e[i]) - int(e[i - 1])) == 1:
					t = 1
				else:
					t = 0
					break
			if t == 1 and 9 < int(e) < k:
				l.append(int(e))
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		res = []
		for num in arr:
			if num < k:
				num_str = str(num)
				if len(num_str) > 1 and all((abs(int(num_str[i]) - int(num_str[i - 1])) == 1 for i in range(1, len(num_str)))):
					res.append(num)
		if len(res) < 1:
			return [-1]
		return res


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		for i in arr:
			if i < k:
				l.append(i)
		for i in l:
			if i <= 9:
				l.remove(i)
		l0 = []
		for i in l:
			l1 = str(i)
			j = 0
			k = len(l1) - 1
			while j < k:
				if abs(int(l1[j]) - int(l1[j + 1])) == 1:
					j = j + 1
					if j == k:
						l0.append(int(l1))
					continue
				else:
					break
		return l0


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ar = []
		bl = False
		for e in arr:
			if e < k:
				bl = True
				st = str(e)
				ls = list(st)
				if len(ls) == 1:
					bl = True
					continue
				valPrv = int(st[0])
				for e2 in st[1:]:
					val = int(e2)
					if not abs(val - valPrv) == 1:
						bl = False
						break
					valPrv = val
				if bl:
					ar.append(e)
		return ar


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		a = []
		for i in arr:
			if i < k:
				a.append(i)
		ans = []
		for i in a:
			x = str(i)
			an = [*x]
			if len(an) > 1:
				n = 0
				for j in range(0, len(an) - 1):
					if int(an[j]) - int(an[j + 1]) == 1 or int(an[j + 1]) - int(an[j]) == 1:
						n += 1
				if n == len(an) - 1:
					ans.append(i)
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		p = [x for x in arr if x < k and x > 9]
		j = len(p)
		if len(p) < 1:
			return [-1]
		else:
			ans = []
			b = 0
			for i in range(j):
				s = str(p[i])
				for z in range(len(s) - 1):
					if abs(int(s[z]) - int(s[z + 1])) == 1:
						b = 1
					else:
						b = 0
						break
				if b == 1:
					ans.append(s)
			if len(ans) > 0:
				return ans
			else:
				return [-1]


import math

class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		result = []
		temp = 0
		for i in arr:
			temp1 = i
			if i < k and len(str(i)) > 1:
				flag = 0
				while i > 0:
					flag = 0
					last = i % 10
					if temp - last == 1 or temp - last == -1:
						flag = 1
					temp = last
					if flag == 0 and i != temp1:
						break
					i = i // 10
				if flag == 1:
					result.append(temp1)
		return result


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		output = []
		for item in arr:
			if item >= k or item < 10:
				continue
			num = str(item)
			flag = True
			for i in range(len(num) - 1):
				if abs(int(num[i]) - int(num[i + 1])) != 1:
					flag = False
					break
			if flag:
				output.append(item)
		return output


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		lst = []
		for i in range(len(arr)):
			if arr[i] < k:
				x = [int(x) for x in str(arr[i])]
				p = 0
				if len(x) > 1:
					for j in range(1, len(x)):
						if abs(x[j] - x[j - 1]) == 1:
							p = 1
						else:
							p = 0
							break
					if p == 1:
						lst.append(arr[i])
		return lst


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		res = []
		for i in arr:
			if i < k:
				if len(str(i)) == 1:
					continue
				for j in range(len(str(i)) - 1):
					if int(str(i)[j]) - int(str(i)[j + 1]) == 1 or int(str(i)[j]) - int(str(i)[j + 1]) == -1:
						continue
					break
				else:
					res.append(i)
		return res


def absdiff(i):
	digits = str(i)
	for x in range(len(digits) - 1):
		if abs(int(digits[x + 1]) - int(digits[x])) != 1:
			return 0
	return 1

class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		output = list()
		for i in arr:
			if i < k and absdiff(i) and (len(str(i)) >= 2):
				output.append(i)
		return output


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		p = []
		for elem in arr:
			if elem < k and elem >= 10:
				valid = True
				s = str(elem)
				d = [int(i) for i in s]
				for index in range(len(s) - 2):
					if abs(d[index] - d[index + 1]) != 1:
						valid = False
						break
				valid = False if abs(d[-1] - d[-2]) != 1 else valid
				p.append(elem) if valid else None
		return p


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		a = []
		for i in arr:
			if i < k:
				x = str(i)
				y = len(x)
				flg = 0
				if y > 1:
					for j in range(y - 1):
						if abs(int(x[j]) - int(x[j + 1])) != 1:
							flg = 1
							break
					if flg == 0:
						a.append(i)
		return a


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in arr:
			if i < k and len(str(i)) > 1:
				temp = str(i)
				if all((abs(int(temp[j]) - int(temp[j - 1])) == 1 for j in range(1, len(temp)))):
					ans.append(i)
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		returnArray = []
		for element in arr:
			if element < k and element > 9:
				itis = True
				changed = element
				while changed > 9:
					last = changed % 10
					changed = changed // 10
					first = changed % 10
					if abs(first - last) != 1:
						itis = False
						break
				if itis == True:
					returnArray.append(element)
		return returnArray


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		list_num = []
		for i in arr:
			if i < k:
				str_num = str(i)
				if len(str_num) > 1:
					for (count, j) in enumerate(str_num[:len(str_num) - 1]):
						if abs(int(j) - int(str_num[count + 1])) != 1:
							break
					else:
						list_num.append(i)
		return list_num


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		result = []

		def check_digits(num_str):
			for j in range(len(num_str) - 1):
				if int(num_str[j]) - int(num_str[j + 1]) not in [1, -1]:
					return False
			return True
		for num in arr:
			if num < k and len(str(num)) > 1:
				if check_digits(str(num)):
					result.append(num)
		return result


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		temp = [str(i) for i in arr if i < k]
		res = []
		for i in temp:
			flag = 0
			if len(i) > 1:
				for j in range(len(i) - 1):
					if abs(int(i[j]) - int(i[j + 1])) == 1:
						pass
					else:
						flag = 1
						break
				if flag == 0:
					res.append(int(i))
		return res


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		li = []
		for i in range(len(arr)):
			if arr[i] < k:
				n = arr[i]
				prev = n % 10
				n = n // 10
				while n > 0:
					curr = n % 10
					if abs(prev - curr) != 1:
						flag = 1
						break
					n = n // 10
					if n == 0:
						li.append(arr[i])
					prev = curr
		return li


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		for i in arr:
			if i < k and i >= 10:
				v = list(str(i))
				c = 1
				for j in range(len(v) - 1):
					if abs(int(v[j]) - int(v[j + 1])) == 1:
						c = c + 1
					else:
						break
				if c == len(v):
					l.append(i)
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in arr:
			if i > 9 and i < k:
				m = list(str(i))
				t = 0
				for j in range(1, len(m)):
					if abs(int(m[j]) - int(m[j - 1])) != 1:
						t = 1
						break
				if t == 0:
					ans.append(i)
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		p = []
		for i in range(n):
			if arr[i] < k:
				p.append(arr[i])
		z = []
		for i in range(len(p)):
			q = str(p[i])
			mx = 0
			for i in range(len(q) - 1):
				diff = int(q[i]) - int(q[i + 1])
				deff = int(q[i + 1]) - int(q[i])
				if diff == 1 or deff == 1:
					mx += 1
				else:
					break
			if mx == len(q) - 1 and mx > 0:
				z.append(int(q))
		return z


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		for i in arr:
			if i < k and len(str(i)) > 1:
				ll = [int(ii) for ii in str(i)]
				temp = 1
				for j in range(1, len(ll)):
					if abs(ll[j - 1] - ll[j]) != 1:
						temp = 0
				if temp == 1:
					l.append(i)
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		res = []
		for elem in arr:
			if elem < k and elem > 9:
				currRem = elem % 10 + 1
				temp = elem
				flag = 0
				while elem > 0:
					rem = elem % 10
					if abs(currRem - rem) == 1:
						currRem = rem
						elem = int(elem / 10)
						continue
					else:
						flag = 1
						break
				if flag == 0:
					res.append(temp)
		return res


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		li = []
		f = False
		for i in range(n):
			if arr[i] < k:
				n = arr[i]
				d = []
				while n > 0:
					d.append(n % 10)
					n = n // 10
				for j in range(len(d) - 1):
					if abs(d[j] - d[j + 1]) == 1:
						f = True
					else:
						f = False
						break
				if f:
					li.append(arr[i])
					f = False
		return li


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		newList = []
		for i in range(n):
			if arr[i] < k and len(str(arr[i])) > 1:
				oper = arr[i]
				flag = True
				for j in range(len(str(oper)) - 1):
					if abs(int(str(oper)[j]) - int(str(oper)[j + 1])) != 1:
						flag = False
						break
				if flag:
					newList.append(oper)
		return newList


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		x = []
		for i in arr:
			if i < k:
				z = str(i)
				if len(z) >= 2:
					c = 0
					for j in range(len(z) - 1):
						if abs(int(z[j]) - int(z[j + 1])) == 1:
							c += 1
						if c == len(z) - 1:
							x.append(i)
		return x


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		a = []
		for i in arr:
			if i < k and len(str(i)) >= 2:
				a.append(i)
		r = []
		for i in a:
			k = str(i)[::-1]
			c = 0
			for j in range(len(k) - 1):
				if abs(int(k[j]) - int(k[j + 1])) == 1:
					c += 1
			if c == len(k) - 1:
				r.append(i)
		return r


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		res = []
		for num in arr:
			if num < k:
				if self.adj(num):
					res.append(num)
		return res

	def adj(self, num):
		if num // 10 == 0:
			return False
		last = num % 10
		num = num // 10
		flag = True
		while num > 0:
			if num % 10 != last + 1 and num % 10 != last - 1:
				return False
			last = num % 10
			num = num // 10
		return True


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		for i in range(n):
			if arr[i] < k:
				c = 0
				nums = [int(j) for j in str(arr[i])]
				if len(nums) > 1:
					for j in range(0, len(nums) - 1):
						if abs(nums[j] - nums[j + 1]) != 1:
							c = 1
				else:
					c = 1
				if c == 0:
					l.append(arr[i])
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		l2 = []
		for i in arr:
			if i < k:
				l.append(i)
		for i in l:
			flag = True
			test = i
			if i < 10:
				flag = False
			else:
				while test >= 10:
					rem10 = test % 10
					test = test // 10
					if test != 0:
						rem100 = test % 10
					else:
						break
					if abs(rem10 - rem100) != 1:
						flag = False
				if flag == True:
					l2.append(i)
		return l2


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		b = [i for i in arr if i < k]
		c = []
		for i in b:
			x = list(map(int, list(str(i))))
			f = True
			if len(x) == 1:
				f = False
			for j in range(len(x) - 1):
				if abs(x[j] - x[j + 1]) != 1:
					f = False
					break
			if f:
				c.append(i)
		return c


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		a = []
		for i in range(n):
			if arr[i] < k:
				v = arr[i]
				c = v % 10
				v = v // 10
				while v > 0:
					l = v % 10
					if abs(c - l) != 1:
						break
					v = v // 10
					if v == 0:
						a.append(arr[i])
					c = l
		return a


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):

		def process(num):
			prev = -1
			temp = num
			while temp != 0:
				val = temp % 10
				if prev != -1:
					if abs(prev - val) != 1:
						return False
				prev = val
				temp = temp // 10
			return True
		if k < 10:
			return []
		res = []
		for i in arr:
			if i < 10 or i >= k:
				pass
			elif process(i):
				res.append(i)
		return res


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		nlist = []
		for i in range(n):
			if arr[i] < k:
				number = arr[i]
				f = 0
				if number < 10:
					f = 1
				while number > 10:
					nu = number % 10
					number = number // 10
					nu2 = number % 10
					if abs(nu - nu2) != 1:
						f = 1
				if f == 0:
					nlist.append(arr[i])
		return nlist


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in arr:
			if i >= 10 and i < k:
				s = str(i)
				c = int(s[0])
				s_n = len(s)
				for j in range(1, len(s)):
					c = abs(c - int(s[j]))
					if c == 1:
						c = int(s[j])
						s_n -= 1
				if s_n == 1:
					ans.append(i)
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		falg = False
		for i in range(n):
			if arr[i] < k:
				num = arr[i]
				dii = []
				while num > 0:
					dii.append(num % 10)
					num //= 10
				for j in range(len(dii) - 1):
					if abs(dii[j] - dii[j + 1]) == 1:
						falg = True
					else:
						falg = False
						break
				if falg:
					ans.append(arr[i])
					falg = False
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		result = []
		for i in range(0, n):
			if arr[i] < k and int(arr[i] / 10) != 0:
				numb = arr[i]
				temp = []
				while numb > 0:
					temp.append(numb % 10)
					numb = int(numb / 10)
				flag = True
				for j in range(0, len(temp) - 1):
					if abs(temp[j] - temp[j + 1]) != 1:
						flag = False
						break
				if flag:
					result.append(arr[i])
		return result


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		res = []
		for i in range(n):
			if (arr[i] < k) & (arr[i] > 9):
				val = 1
				for j in range(len(str(arr[i])) - 1):
					val = (int(str(arr[i])[j]) - int(str(arr[i])[j + 1])) * val
				if (val == 1) | (val == -1):
					res.append(arr[i])
		return res


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		num_lt_k = [list(str(i)) for i in arr if i < k]
		result = []
		for s in num_lt_k:
			if len(s) >= 2:
				absolutes = [True if abs(int(s[i]) - int(s[i + 1])) == 1 else False for i in range(len(s) - 1)]
				if all(absolutes):
					result.append(int(''.join(s)))
		return result


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in range(n):
			if arr[i] < k and arr[i] > 9:
				flag = True
				element = arr[i]
				while element > 9:
					last = element % 10
					element = element // 10
					first = element % 10
					if abs(last - first) != 1:
						flag = False
						break
				if flag:
					ans.append(arr[i])
		return ans


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		lst = []
		for i in range(n):
			t = 0
			if arr[i] < k:
				for j in range(len(str(arr[i])) - 1):
					if abs(int(str(arr[i])[j]) - int(str(arr[i])[j + 1])) == 1:
						t = t + 1
					if t == len(str(arr[i])) - 1:
						lst.append(arr[i])
		return lst


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		flag = False
		for i in range(n):
			if arr[i] < k:
				num = arr[i]
				di = []
				while num > 0:
					di.append(num % 10)
					num //= 10
					for j in range(len(di) - 1):
						if abs(di[j] - di[j + 1]) == 1:
							flag = True
						else:
							flag = False
							break
			if flag:
				l.append(arr[i])
				flag = False
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		(i, j) = (0, 0)
		l = []
		while i < n:
			if arr[i] < k and arr[i] > 9:
				x = arr[i]
				while x > 9:
					r = x % 10
					x = x // 10
					c = x % 10
					if abs(r - c) != 1:
						j = 1
						break
				if j == 0:
					l.append(arr[i])
				j = 0
			i += 1
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):

		def helper(num):
			arr = list(str(num))
			n = len(arr)
			if n <= 1:
				return False
			for i in range(0, n - 1):
				if abs(int(arr[i + 1]) - int(arr[i])) != 1:
					return False
			return True
		res = []
		for ele in arr:
			if ele < k and helper(ele) == True:
				res.append(ele)
		return res


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		for i in arr:
			if i < k and i > 9:
				r = 0
				n = i
				s = n % 10
				n = n // 10
				f = 1
				while n > 0:
					r = n % 10
					n = n // 10
					if abs(s - r) == 1:
						f = 1
					else:
						f = 0
						break
					s = r
				if f == 1:
					l.append(i)
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		for i in range(n):
			if arr[i] > 9 and arr[i] < k:
				a = str(arr[i])
				b = 0
				for j in range(len(a) - 1):
					if abs(int(a[j]) - int(a[j + 1])) == 1:
						pass
					else:
						b = 1
						break
				if b == 0:
					l.append(arr[i])
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		l = []
		for i in range(n):
			if arr[i] < k and len(str(arr[i])) > 1:
				a = list(str(arr[i]))
				for j in range(len(a) - 1):
					if abs(int(a[j]) - int(a[j + 1])) == 1:
						x = 1
					else:
						x = 0
						break
				if x == 1:
					l.append(arr[i])
		return l


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		ans = []
		for i in range(n):
			flag = 0
			temp = str(arr[i])
			for j in range(1, len(temp)):
				if abs(ord(temp[j - 1]) - ord(temp[j])) != 1:
					flag = 1
					break
			if flag == 0 and arr[i] < k and (len(temp) > 1):
				ans.append(arr[i])
		return ans


def diffNum(num):
	if num // 10 == 0:
		return False
	diff = 0
	(x, num) = (num % 10, num // 10)
	while num > 0:
		y = x
		x = num % 10
		if abs(x - y) != 1:
			return False
		num = num // 10
	return True

class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		arr = [i for i in arr if i < k]
		result = []
		for i in arr:
			if diffNum(i):
				result.append(i)
		return result


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		result = []
		for num in arr:
			if num < k:
				ele = num
				flag = 1
				digit = ele % 10
				ele = ele // 10
				while ele:
					if abs(ele % 10 - digit) != 1:
						flag = 0
						break
					digit = ele % 10
					ele = ele // 10
				if flag and num > 9:
					result.append(num)
		return result


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):
		count = []
		for x in arr:
			if x < k and x > 9:
				flag = 1
				value = x
				digit1 = value % 10
				value = value // 10
				while value:
					digit2 = value % 10
					if abs(digit1 - digit2) != 1:
						flag = 0
						break
					digit1 = digit2
					value = value // 10
				if flag == 1:
					count.append(x)
		return count


class Solution:

	def getDigitDiff1AndLessK(self, arr, n, k):

		def get_num(num):
			b = -1
			while num > 0:
				a = num % 10
				if a > -1 and b > -1:
					if abs(a - b) != 1:
						return -1
				num = num // 10
				b = a
			return 1
		result = []
		for each in arr:
			if each < k and each > 9:
				temp = get_num(each)
				if temp > 0:
					result.append(each)
		return result