Binary Search
Demo
Star Sum
Amazon Online Assessment
E-Mart Product Ranking
Amazon Online Assessment
Minimum Total Wattage
Amazon Online Assessment
Best Stock Combos
Amazon Online Assessment Subset
Split String
Amazon Online Assessment Array
Find Pairs
Amazon Online Assessment Array
Merge Adjacent Numbers
Amazon Online Assessment Array
Split Array III
Amazon Online Assessment Array
Minimum Number of Swaps
Amazon Online Assessment Array
Collection of Circles
Google Onsite MST
Search Extensible String
New Google Onsite
Maximum Deviation Among All Substrings
Online Assessment String
Maximum Greyness
New Online Assessment Matrix
Separate Pages
New Online Assessment Bit
Shop for Clothes on a Budget
New Online Assessment
Color Palette
Online Assessment Array
Min Appends to Make Subsequence
Online Assessment String
Min Swaps to Partition
New Online Assessment
Minimum Net Price Change
New Online Assessment Intern Array
Channels Maximum Quality
New Online Assessment
Slice Array
New Online Assessment Array
Stock Fluctuation
New Online Assessment Array
Decoding String
New Online Assessment String
Maximum Precipitation
New Online Assessment
Count Reviews II
New Online Assessment
Count Reviews Combinations
New Online Assessment
LRU Browser History
New Online Assessment
Split Array II
Amazon Google New
Load Cargo
Amazon Google New
Split Array
Amazon Google New
Find Bridges In A Graph
Amazon Google MST New
Closest Pair of Molecules
Google Amazon New
Search Matrix
Facebook New
Max Submatrix Sum
Google Facebook New
Cache Hit Ratio
Google Facebook Amazon New
Find Cut Vertices
Google Amazon New
Two Sum Smaller Than Target
Google Amazon New
Can Make Palindrome
Facebook New
Discount Calculator
Amazon New Online Assessment
Max Sink Area
Amazon New
Measure Island Border
Facebook New
Construct Word Using Dice
Google New
Recursive Islands and Lakes
Google Hard New
Packaging Automation
Amazon New Online Assessment
Secret Fruit List
Amazon Online Assessment New
Find Related Products
Amazon Online Assessment New
Optimize Memory Usage
Online Assessment
Min Cost To Add New Roads
Online Assessment
Connect Ropes
Amazon Online Assessment
Pizza Shop
Google Phone
Least Common Ancestor Of Multiple Nodes
Amazon Phone Tree
Remove Duplicated IPv4 Addresses
Amazon Onsite
Fibonacci Base I
Google
Activate Fountain
Twitter Online Assessment
Reaching Point
Twitter Online Assessment
K-Difference
Twitter Online Assessment
Find Critical Nodes
Amazon Online Assessment
Zombie Matrix
Amazon HOT
Data Center Critical Connection
Amazon Online Assessment
Min Cost to Repair Edges (Minimum Spanning Tree II)
Amazon Online Assessment MST Graph
Rose Garden
Google Online Assessment
Minimum Number Of Decreasing Subsequence Partitions
Google Online Assessment Hard DP
Cut Binary Search Tree
Amazon Tree BST Hard LC
Subtree: Maximum Average Node
Amazon Online Assessment Medium Tree
Fill 2D Array
Google Online Assessment
Rearrange String
String
Pickup Coupon
Google Online Assessment
Tree Diameter
Google
Top N Buzzwords
Amazon Online Assessment HOT
Load Balancer
Amazon Online Assessment
Find Substrings
Amazon Online Assessment Hard
Partition String
Amazon Online Assessment String Medium

Utilization Checks

A risk modeling system uses a scaling computing system that implements an autoscale policy depending on the current load or utilization of the computing system.
The system starts with a number of computing instances given by instances. The system polls the instances every second to see the average utilization at that second, and performs scaling as described below. Once any action is taken, the system will stop polling for 10 seconds. During that time, the number of instances does not change.
Average utilization > 60%: Double the number of instances if the doubled value does not exceed 2 * 10^8. This is an action. If the number of instances exceeds this limit on doubling, perform no action.
Average utilization < 25%: Halve the number of instances if the number of instances is greater than 1 (take ceil if the number is not an integer). This is also an action. If the number of instances is 1, take no action.
25% <= Average utilization <= 60%: No action.
Given an array of the values of the average utilization at each second for this system, determine the number of instances at the end of the time frame.
For example, the system starts with instances = 2, and average utilization is given as averageUtil = [25, 23, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 76, 80].
At the first second, utilization is 25, so no action is taken.
At the second second, averageUtil[1] = 23 < 25, so instances = 2 / 2 = 1. The next 10 seconds, averageUtil[2]..averageUtil[11], no polling is done.
At averageUtil[11] = 76, 76 > 60 so the number of instances is doubled. There are no more readings to consider and 2 is the final answer.

Constraints:
1 <= instances <= 10^5
1 <= n <= 10^5
1 <= averageUtil[i] <= 100

Example 1:
Input: averageUtil=[5, 10, 80], instances = 1
Output: 2
Explanation:
Here instance = 1 and averageUtil = [5, 10, 80]. At the 1st and 2nd seconds of the time period, no action will be taken because the utilization is less than 25%, the number of instance is 1. At the 3rd second, the number of instances will double to 2.

Example 2:
Input: averageUtil=[30, 5, 4, 8, 19, 89], instances = 5
Output: 3
Explanation:
At second 1,25 <= averageUtil[0] = 30 <= 60, so take no action.
At second 2, averageUtil[1] = 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 averageUtil[2] through averageUtil[5] no actions will be taken.
There are no more readings to consider and 3 is the final answer.


Python


def finalInstances(instances, averageUtil): """ :type instances: int :type averageUtil: List[int] :rtype: int """