Find instances at end of time frame after auto scaling | Python program for the above approach ; Function to find the number of instances after completion ; Traverse the array , arr [ ] ; If current element is less than 25 ; Divide instances by 2 ; If the current element is greater than 60 ; Double the instances ; Print the instances at the end of the traversal ; Driver Code ; Function Call
from math import ceil NEW_LINE def finalInstances ( instances , arr ) : NEW_LINE INDENT i = 0 NEW_LINE while i < len ( arr ) : NEW_LINE INDENT if arr [ i ] < 25 and instances > 1 : NEW_LINE INDENT instances = ceil ( instances / 2 ) NEW_LINE i += 10 NEW_LINE DEDENT elif arr [ i ] > 60 and instances <= 10 ** 8 : NEW_LINE INDENT instances *= 2 NEW_LINE i += 10 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT print ( instances ) NEW_LINE DEDENT instances = 2 NEW_LINE arr = [ 25 , 23 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 76 , 80 ] NEW_LINE finalInstances ( instances , arr ) NEW_LINE