# Find instances at end of time frame after auto scaling

Given an integer, instances, and an array, arr[] of size N representing the average utilization percentage of the computing system at each second, the task is to find the number of instances at the end of the time frame such that the computing system auto-scales the number of instances according to the following rules: Average utilization < 25%: Reduce the number of instances by half if the number of instances is greater than 1.25% ≤ Average utilization ≤ 60%: Take no action.Average utilization > 60%: Double the number of instances if the doubled value does not exceed 2* 108.Once an action of adding or reducing the number of instances is performed, the system will stop monitoring for 10 seconds. During that time, the number of instances does not change.Examples:Input: instances = 2, arr[] = {25, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 76, 80}Output: 2Explanation:At second 1, arr = 25 ≤ 25, so take no action.At second 2, arr = 23 < 25, so an action is instantiated to halve the number of instances to ceil(2/2) = 1. The system will stop checking for 10 seconds, so from arr through arr no actions will be taken.At second 13, arr = 76 > 60, so the number of instances is doubled from 1 to 2.There are no more readings to consider and 2 is the final value.Input: instances = 5, arr = {30, 5, 4, 8, 19, 89}Output: 3Explanation:At second 1, 25 ≤ arr = 30 ≤ 60, so take no action.At second 2, arr = 5 < 25, so an action is instantiated to halve the number of instances to ceil(5/2) = 3.The system will stop checking for 10 seconds, so from arr through arr no actions will be taken.There are no more readings to consider and 3 is the final answer.Approach: The given problem can be solved by traversing the given array arr[] and if the current element is less than 25 then divide the number of instances by 2 if the number of instances is greater than 1. Otherwise, if the current value is greater than 60 multiply the number of instances by 2 if the number of instances is not greater than 108, after performing either of the two operations increment the current index by 10. Follow the steps to solve the problem:Traverse the array, arr[] using the variable i and perform the following steps:If arr[i] is less than 25 and instances is greater than 1, divide the instances by 2 and increment i by 10.If arr[i] is greater than 60 and instances is less than or equal to 108, multiply instances by 2 and increment i by 10.Increment the index i by 1.After completing the above steps, print the number of instances as the result.Below is the implementation of the above approach:Python3from math import ceil  def finalInstances(instances, arr):    i = 0          while i < len(arr):                          if arr[i] < 25 and instances > 1:                                    instances = ceil(instances / 2)            i += 10                          elif arr[i] > 60 and instances 