human
Maximum number of Armstrong Numbers present in a subarray of size K | Function to calculate the value of x raised to the power y in O ( log y ).
Base Case.
If the power y is even.
Otherwise.
Function to calculate the order of the number , i . e . count of digits.
Stores the total count of digits.
Iterate until num is 0.
Function to check a number is an Armstrong Number or not.
Find the order of the number.
Check for Armstrong Number.
If Armstrong number condition is satisfied.
Utility function to find the maximum sum of a subarray of size K.
If k is greater than N.
Find the sum of first subarray of size K.
Find the sum of the remaining subarray.
Return the maximum sum of subarray of size K.
Function to find all the Armstrong Numbers in the array.
Traverse the array arr [ ].
If arr [ i ] is an Armstrong Number , then replace it by 1. Otherwise , 0.
Return the resultant count.
Driver Code"
Solution in Python:
assistant
#Here is code to maximum number of Armstrong Numbers present in a subarray of size K and the other steps required.
 def power ( x , y ) :
	if ( y == 0 ) :
		return 1
	if ( y % 2 == 0 ) :
		return power ( x , y // 2 ) * power ( x , y // 2 )
	return x * power ( x , y // 2 ) * power ( x , y // 2 )
def order ( num ) :
	count = 0
	while ( num ) :
		count += 1
		num = num // 10
	return count
def isArmstrong ( N ) :
	r = order ( N )
	temp = N
	sum = 0
	while ( temp ) :
		d = temp % 10
		sum += power ( d , r )
		temp = temp // 10
	return ( sum == N )
def maxSum ( arr , N , K ) :
	if ( N < K ) :
		return - 1
	res = 0
	for i in range ( K ) :
		res += arr [ i ]
	curr_sum = res
	for i in range ( K , N , 1 ) :
		curr_sum += arr [ i ] - arr [ i - K ]
		res = max ( res , curr_sum )
	return res
def maxArmstrong ( arr , N , K ) :
	for i in range ( N ) :
		arr [ i ] = isArmstrong ( arr [ i ] )
	return maxSum ( arr , N , K )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 28 , 2 , 3 , 6 , 153 , 99 , 828 , 24 ]
	K = 6
	N = len ( arr )
	print ( maxArmstrong ( arr , N , K ) )