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.

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*

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

*Related:*

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

*Weekly Contest 247*

*Weekly Contest 247*

- Maximum Product Difference Between Two Pairs
- Cyclically Rotating a Grid
- Number of Wonderful Substrings
- Count Ways to Build Rooms in an Ant Colony

*Biweekly Contest 55*

*Biweekly Contest 55*

- Remove One Element to Make the Array Strictly Increasing
- Remove All Occurrences of a Substring
- Maximum Alternating Subsequence Sum
- Design Movie Rental System

*June Long Challenge 2021 Solutions*

*June Long Challenge 2021 Solutions*

*Maximum Frequent Subarray Sum solution codechef**Dual Distance solution codechef**Optimal Xor Set solution codechef**Minimum Subtree Cover solution codechef**Minimum Dual Area solution codechef**Bitwise Tuples solution codechef**Shortest Route solution codechef**Bella ciao solution codechef**Summer Heat solution codechef*