Pappu is confused between 6 & 9. He works in the billing department of abc company and his work is to return the remaining amount to the customers. If the actual remaining amount is given we need to find the maximum possible extra amount given by the pappu to the customers.
Example 1:
Input: amount = 56
Output: 3
Explanation: maximum possible extra 
             amount = 59 - 56 = 3.
Example 2:
Input: amount = 66
Output: 33
Explanation: maximum possible extra 
             amount = 99 - 66 = 33.
User Task:
Your task is to complete the function findDiff() which takes single argument(amount) and returns the answer. You need not take any input or print anything.
Expected Time Complexity: O(log_{10}amount).
Expected Auxiliary Space: O(log_{10}amount).
Constraints
1 ≤ N≤ 10000001

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Mathematics

Starter code: #User function Template for python3

class Solution:

    def findDiff(self, amount):
        # code here

Solutions:
class Solution:

	def findDiff(self, amount):
		str1 = str(amount)
		str2 = ''
		for i in range(len(str1)):
			if str1[i] == '6':
				str2 = str2 + '9'
			else:
				str2 = str2 + str1[i]
		num = int(str2)
		res = num - amount
		return res


class Solution:

	def findDiff(self, amount):
		r = ''
		for i in str(amount):
			if i == '6':
				r += '9'
			else:
				r += i
		if int(r) > amount:
			return int(r) - amount
		else:
			return amount - int(r)


class Solution:

	def findDiff(self, s):
		p = str(s)
		k = p.replace('6', '9')
		return abs(int(k) - int(p))


class Solution:

	def findDiff(self, amount):
		a = amount
		aa = str(a)
		stri = ''
		for i in aa:
			if i == '6':
				stri += '9'
			else:
				stri += i
		bb = int(stri)
		return abs(bb - amount)


class Solution:

	def findDiff(self, amount):
		lastDigit = str(amount)
		lastDigit = int(lastDigit.replace('6', '9')) - int(lastDigit)
		return int(lastDigit)


class Solution:

	def findDiff(self, amount):
		ans = ''
		for i in str(amount):
			if i == '6':
				ans += '9'
			else:
				ans += i
		return abs(int(ans) - int(amount))


class Solution:

	def findDiff(self, amount):
		lp = str(amount)
		kl = lp.replace('6', '9')
		return abs(int(kl) - int(amount))


class Solution:

	def findDiff(self, a):
		s = ''
		for i in str(a):
			if i == '6':
				s = s + '9'
			else:
				s = s + i
		return abs(int(s) - a)


class Solution:

	def findDiff(self, amount):
		t = amount
		a = str(amount)
		s = a.replace('6', '9')
		k = int(s)
		return k - t


class Solution:

	def findDiff(self, amount):
		b = str(amount)
		a = int(b.replace('6', '9'))
		sum = a - int(b)
		return sum


class Solution:

	def findDiff(self, amount):
		s = str(amount)
		res = ''
		for i in s:
			if i == '6':
				res += '9'
			else:
				res += i
		return int(res) - amount


class Solution:

	def findDiff(self, amount):
		a = str(amount)
		if '6' in a:
			a = a.replace('6', '9')
		return abs(int(a) - amount)


class Solution:

	def findDiff(self, amount):
		st = str(amount)
		ans1 = ''
		ans2 = ''
		for i in st:
			if i == '6':
				ans1 = ans1 + '9'
			else:
				ans1 = ans1 + i
		t = int(ans1)
		return abs(t - amount)


class Solution:

	def findDiff(self, amount):
		p = amount
		amount = list(str(amount))
		res = 0
		for i in range(len(amount)):
			if amount[i] == '6':
				amount[i] = '9'
		amount = ''.join(amount)
		amount = int(amount)
		res = amount - p
		if res < 0:
			res = res * -1
		return res


class Solution:

	def findDiff(self, amount):
		amt = str(amount)
		amt1 = ''
		for i in amt:
			if i == '6':
				amt1 += '9'
			else:
				amt1 += i
		return int(amt1) - int(amt)


class Solution:

	def findDiff(self, amount):
		sum = 0
		temp = amount
		while temp != 0:
			m = temp % 10
			if m == 6:
				m = 9
			sum = sum * 10 + m
			temp //= 10
		sum1 = int(str(sum)[::-1])
		return sum1 - amount


class Solution:

	def findDiff(self, amount):
		diff = 0
		correct_amount = str(amount)
		correct_amount = correct_amount.replace('6', '9')
		final_amount = int(correct_amount)
		if final_amount > amount:
			diff = final_amount - amount
		return diff


class Solution:

	def findDiff(self, amount):
		str_amount = str(amount)
		extra_amount_str = ''
		for i in str_amount:
			if i == '6':
				extra_amount_str += '9'
			else:
				extra_amount_str += i
		extra_amount = int(extra_amount_str)
		return extra_amount - amount


class Solution:

	def findDiff(self, amount):
		x = list(str(amount))
		for i in range(len(x)):
			if x[i] == '9':
				x[i] = '6'
			if x[i] == '6':
				x[i] = '9'
		return abs(int(''.join(x)) - amount)


class Solution:

	def findDiff(self, amount):
		s = str(amount)
		s1 = ''
		for i in s:
			if i == '6':
				s1 += '9'
			else:
				s1 += i
		no = int(s1)
		return abs(amount - no)


class Solution:

	def findDiff(self, amount):
		n = amount
		s = 0
		while n > 0:
			r = n % 10
			if r == 6:
				r = 9
			s = s * 10 + r
			n = n // 10
		p = 0
		while s > 0:
			r = s % 10
			p = p * 10 + r
			s = s // 10
		return p - amount


class Solution:

	def findDiff(self, amount):
		x = str(amount)
		r = ''
		n = 0
		for i in range(len(x)):
			if x[i] == '6':
				r += '9'
			else:
				r += x[i]
		m = int(r)
		return abs(amount - m)


class Solution:

	def findDiff(self, amount):
		amount = str(amount)
		amount1 = amount.replace('6', '9')
		result = int(amount1) - int(amount)
		return result


class Solution:

	def findDiff(self, amount):
		ori = amount
		a = str(amount)
		b = ''
		for i in a:
			if i == '6':
				b += '9'
			else:
				b += i
		return abs(ori - int(b))


class Solution:

	def findDiff(self, amount):
		s = '6'
		n = '9'
		k = ''
		a = str(amount)
		for i in a:
			if i == s:
				k += n
			else:
				k += i
		return int(k) - amount


class Solution:

	def findDiff(self, amount):
		b = str(amount)
		for i in b:
			if i == '6':
				b = b.replace(i, '9')
		return int(b) - amount


class Solution:

	def findDiff(self, amount):
		y = ''
		z = str(amount)
		for i in range(len(z)):
			if z[i] != '6':
				y = y + z[i]
			else:
				y = y + '9'
		y = int(y)
		return abs(amount - y)


class Solution:

	def findDiff(self, amount):
		x = str(amount)
		y = ''
		for i in x:
			if i == '6':
				y += '9'
			else:
				y += i
		return int(y) - amount


class Solution:

	def findDiff(self, amount):
		s = str(amount).replace('6', '3')
		return amount - int(s)


class Solution:

	def findDiff(self, amount):
		a = ''
		res = [int(x) for x in str(amount)]
		for i in range(len(res)):
			if res[i] == 6:
				res[i] = 9
		for i in range(len(res)):
			a += str(res[i])
		a = int(a)
		return a - amount


class Solution:

	def findDiff(self, n):
		n = str(n)
		str2 = ''
		for i in n:
			if i == '6':
				str2 += '9'
			else:
				str2 += i
		str2 = int(str2)
		return str2 - int(n)


class Solution:

	def findDiff(self, amount):
		k = str(amount)
		for i in k:
			if '6' in k:
				k1 = k.replace('6', '9')
				return int(k1) - amount
			else:
				return 0


class Solution:

	def findDiff(self, amount):
		st = ''
		n = str(amount)
		for i in n:
			if i == '6':
				st += '9'
			else:
				st += i
		diff = int(st) - int(n)
		return diff


class Solution:

	def findDiff(self, amount):
		k = str(amount)
		i = k.replace('6', '9')
		i = int(i)
		k = int(k)
		return i - k


class Solution:

	def findDiff(self, amount):
		s = str(amount)
		for i in s:
			if i == '6':
				s = s.replace(i, '9')
		result = int(s) - amount
		return result


class Solution:

	def findDiff(self, amount):
		st = str(amount)
		if '6' in st:
			st = st.replace('6', '9')
			return int(st) - amount
		return 0


class Solution:

	def findDiff(self, a):
		a = str(a)
		x = a.replace('6', '9')
		return int(x) - int(a)


class Solution:

	def findDiff(self, amount):
		s = list(str(amount))
		k = []
		for i in s:
			k.append(i)
		for i in range(len(k)):
			if k[i] == '6':
				k[i] = '9'
			elif k[i] == '9':
				k[i] == '6'
		s1 = ''
		for i in k:
			s1 += i
		s1 = int(s1)
		s2 = amount
		diff = abs(s1 - s2)
		return diff


class Solution:

	def findDiff(self, amount):
		res = ''
		for x in str(amount)[::-1]:
			if x == '6':
				res += '3'
			else:
				res += '0'
		return int(res[::-1])


class Solution:

	def findDiff(self, amount):
		amou = str(amount)
		string = amou.replace('6', '9')
		return int(string) - amount


class Solution:

	def findDiff(self, amt):
		sub = 0
		counter = 0
		while amt:
			if amt % 10 == 6:
				sub += 10 ** counter * 3
			counter += 1
			amt = amt // 10
		return sub


class Solution:

	def findDiff(self, amount):
		d = ''
		c = str(amount)
		if '6' in c:
			d = c.replace('6', '9')
			return int(d) - amount
		elif '9' in c:
			d = c.replace('9', '6')
			return amount - int(d)
		else:
			return 0


class Solution:

	def findDiff(self, amount):
		x = str(amount)
		y = x.replace('6', '9')
		z = int(y)
		return z - amount


class Solution:

	def findDiff(self, amount):
		amount = str(amount)
		n = ''
		for i in range(len(amount)):
			if amount[i] == '6':
				n += '9'
			else:
				n += amount[i]
		amt = abs(int(n) - int(amount))
		return amt


class Solution:

	def findDiff(self, amount):
		correct = ''
		amount = str(amount)
		for i in amount:
			if i != '6':
				correct += i
			else:
				correct += '9'
		correct = int(correct)
		amount = int(amount)
		result = correct - amount
		return result


class Solution:

	def findDiff(self, amount):
		number = 0
		count = 0
		Amount = amount
		while amount != 0:
			digit = amount % 10
			amount = amount // 10
			if digit == 6:
				digit = 9
			number = number + digit * 10 ** count
			count += 1
		return number - Amount