human
Split the number N by maximizing the count of subparts divisible by K | Function to count the subparts.
Total subStr till now.
If it can be divided , then this substring is one of the possible answer.
Convert string to long long and check if its divisible with X.
Consider there is no vertical cut between this index and the next one , hence take total carrying total substr a ..
If there is vertical cut between this index and next one , then we start again with subStr as " " and add b for the count of subStr upto now.
Return max of both the cases.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to split the number N by maximizing the count of subparts divisible by K and the other steps required.
 def count ( N , X , subStr , index , n ) :
	if ( index == n ) :
		return 0
	a = subStr + N [ index ]
	b = 0
	if ( int ( a ) % X == 0 ) :
		b = 1
	m1 = count ( N , X , a , index + 1 , n )
	m2 = b + count ( N , X , " " , index + 1 , n )
	return max ( m1 , m2 )
N = "00001242"
K = 3
l = len ( N )
print ( count ( N , K , " " , 0 , l ) )