human
Give me a code to minimum number of digits required to be removed to make a number divisible by 4 and the other steps required given the following:
Minimum number of digits required to be removed to make a number divisible by 4 | Function to count the minimum number of digits required to be removed to make a given number divisible by 4.
Store the size of the string.
Stores the required result.
Check for every pair of digits if the number formed by them is divisible by 4 or not.
Store s [ i ] in a variable.
If it is divisible by 2.
Store the number formed by s [ j ] and s [ i ].
Check if it is divisible by 4.
Store the number of digits required to be deleted.
Update ans.
If value of ans is unchanged , then check if any s [ i ] is divisible by 4.
If true , update ans to n - 1.
Prthe result.
Driver Code"
Solution in Python:
assistant
#Here is code to minimum number of digits required to be removed to make a number divisible by 4 and the other steps required.
 def minimumDeletions ( s ) :
	n = len ( s )
	ans = n
	for i in range ( n - 1 , - 1 , - 1 ) :
		t = ord ( s [ i ] ) - ord ( '0' )
		if ( t % 2 == 0 ) :
			for j in range ( i - 1 , - 1 , - 1 ) :
				num = ( ord ( s [ j ] ) - ord ( '0' ) ) * 10 + t
				if ( num % 4 == 0 ) :
					k1 = i - j - 1
					k2 = n - i - 1
					ans = min ( ans , k1 + k2 )
	if ( ans == n ) :
		for i in range ( n ) :
			num = ord ( s [ i ] ) - ord ( '0' )
			if ( num % 4 == 0 ) :
				ans = n - 1
	print ( ans )
if __name__ == ' _ _ main _ _ ' :
	str = "12367"
	minimumDeletions ( str )