Autoscale Policy, Utilization Check Solution Amazon OA 2021

Autoscale Policy, Utilization Check Solution

A scaling computing system checks its average utilization every second while it monitors. It implements an autoscale policy to increase or reduce instances depending on the current load as described below. Once an action of increasing 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.

See Also : Amazon Online Assessment Questions 2021 Preparation

  • If the average utilization < 25%, then an action is instantiated to reduce the number of instances by half if the number of instances is greater than 1. Take the ceiling if the number is not an integer. If the number of instances is 1, take no action.
  • If 25% s average utilization s 60%, take no action.
  • If the average utilization > 60%, then an action is instantiated to double the number of instances if the doubled value does not exceed 2* 108. If the number of instances exceeds this limit upon doubling, take no action.

Given an array of integers that represent the average utilization at each second, determine the number of instances at the end of the time frame.

Example

instances = 2

averageUtil = [25, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 76, 80]

  • At second 1. the average utilization averageUtil[0] = 25 < 25 instances at the end of the time frame.

Example

instances = 2

averageUtil = [25, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 76, 80]

  • At second 1, the average utilization averageUtil[0] =25 s 25, so take no action. . At second 2, the average utilization averageUtil[1] = 23 < 25, so reduce the number of instances by half to get 2/2 – 1.
  • Since an action was taken the system will stop checking for 10 seconds, from averageUtil[2] through averageUtil[11].
  • At averageUtil[12] = 76, 76 > 60, so the number of instances is doubled from 1 to 2. 21 1 22 23 24 25 26

There are no more readings to consider and 2 is the final answer. 27 28

Function Description

Complete the function finalinstances in the editor below.

finalinstances has the following parameter(s):

int instances: the original number of instances running

int averageUtil[n]: the average utilization at each second of the time frame 33 > pub

Returns:

int: the final number of instances running

Constraints .

1 < instances < 10^5

1 < n < 10^5

0 < averageUtil[i] < 100

Input Format For Custom Testing
Sample Case 0
Sample Input For Custom Testing

1
3
5
10
80

Sample Output

2

Solution

Program Python

for j in range( len(avg)):
if avg[j]<25:
if (instance>1):
instance =math.ceil(instance / 2)
j=j+10
if j>len(avg):
break
if avg[j] > 60:
if ((instances*2) < 217):
instance = instance * 2
j=j+10
if j>len(avg):
break
return (instance)

Program Python

def finalInstances (instances, averageUtil):
Autoscale Policy, Utilization Check

Related:

Weekly Contest 247

Biweekly Contest 55

June Long Challenge 2021 Solutions

Leave a Comment

Please Click on 1 or 2 Ads to help us run this site.
+