Page Contents

*Autoscale Policy Utilization Check Solution*

*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.

Also See: Amazon OA Online Assessment 2021 Questions and Answers

- 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*

*Solution*

** Program**: Autoscale Policy Utilization Check Solution in 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*

Also See: AMCAT Study Materials, Preparation Guide

Also See: Microsoft Online Assessment Questions and Solution

**Amazon Online Assessment Questions:**

*Robot Bounded in Box**Number Game**Find All Combination of Numbers Sum to Target / Shopping Options**Fill the Truck**Music Pairs**Slowest key**Five Star Seller**Split String Into Unique Primes**Storage Optimization**Minimum Difficulty of a Job Schedule**Autoscale Policy Utilization Check**Optimal Utilization**Merge Two Sorted Lists**Two Sum Unique Pairs**Shopping Patterns**Reorder Data in Log Files**Top K Frequent Words**Trees Height**Counting Binary Substrings Amazon OA Solution**Grid Connections Amazon OA Solution**Shipment Imbalance Amazon OA Solution**Max Profit Amazon OA Solution**Find Lowest Price Amazon OA Solution**Simple Cipher Amazon OA Solution**Decode String Frequency Amazon OA Solution**Valid Discount Coupons Amazon OA Solution**Count Maximum Teams Amazon OA Solution**Minimum Coin Flips Amazon OA Solution**Stock Price Amazon OA Solution*