Amazon
  • Introduction
  • Phone Interview I
    • 53.Reverse Words in a String
    • 31.Partition Array
  • Phone Interview II
    • 167.Add Two Numbers
    • 88.Lowest Common Ancestor
  • Onsite I
    • 655.Big Integer Addition
    • 221.Add Two Numbers II
  • Onsite II
    • 158.Two Strings Are Anagrams
    • 171.Anagrams
    • 386.Longest Substring with At Most K Distinct Characters
  • Onsite III
    • 479.Second Max of Array
    • 589.Connecting Graph
  • Onsite IV
    • 532.Reverse Pairs
  • 2022
    • OA
      • work simulation
      • Greyness
      • NearestRetailer
      • Sum of Scores of Subarray
      • StrengthOfPassword
      • ProductOf1
      • Move 0/1 InArray
      • Max deviation among all substrings
      • AWS power consumption
      • searchWordResultWord
      • maxOperationOfString
      • MinHealthGame
      • EarliestMonth
      • Package ship
      • RatingConsectiveDecresing
      • LinkedListSum
      • MovingBoxes
      • ValidString
      • MaxValueAfterRemovingFromString
      • Subtree with Maximum Average
    • VO
      • 2022.3
    • BQ
      • doc
      • 2022.4
      • Freq Question
      • 11大类BQ和Follow-ups
      • Page 1
      • BQ 100
      • 35 behavioral questions asked in 95% of Amazon interviews with examples
      • Page 2
      • 反向BQ
    • LP
      • LP-1
      • LP-2
    • SD
      • Design Amazon Prime Video Recommendation System
      • Amazon Order system
    • OOD
      • Linux Find Command
      • Amazon Locker
    • AWS Identity call
    • Interviews
Powered by GitBook
On this page

Was this helpful?

  1. 2022
  2. OA

AWS power consumption

https://leetcode.com/discuss/general-discussion/1700915

PreviousMax deviation among all substringsNextsearchWordResultWord

Last updated 3 years ago

Was this helpful?

Question on AWS power consumption, given BootingPower[i], processingPower[i], powerMax. For maximum utilization, the data center wishes to group these processors into clusters. Clusters can only be formed of processors located adjacent to each other. For example, processors 2,3,4,5 can form a cluster, but 1,3,4 cannot.

cluster of k processors defined as (i, i+1,...., i+k-1)

Net power consumption = maximum booting power among the k processors + (sum of processing power of processors)*k. A cluster is said to be sustainable if it's net power consumption does not exceed a given threshold value powerMax.

Example: bootingPower = [3,6,1,3,4] processingPower = [2,1,3,4,5] powerMax = 25

If k = 2, any adjacent pair can be choosen. The highest usage is the pair [4,5] with net power consumption 4 + (4 + 5)2 = 22. Next, try k = 3. Group the first 3 processors together as: Here, Max booting power = max(3,6,1) Sum of processing power = 2 + 1+ 3 = 6 Net power consumption = 6 + 63 = 24 <= powerMax

Thus, k = 3 is a sustainable cluster.

Example: bootingPower = [8,8,10,9,2] processingPower = [4,1,4,5,3] powerMax = 33

If k = 2, consisting of first 2 processors. Net power consumption = max(8,8) + (4+1)*2 = 18 <= 33 (powerMax)

Thus, k = 2 is a sustainable cluster.

Example: bootingPower = [11,12,19] processingPower = [10,8,7] powerMax = 6

k = 0, not possible to form any sustainable clusters.

Solution:

Guys upvote(will help others), seems like working solution in java, thanks for posting the above question :

public static int findMaximumSustainableClusterSize(List<Integer> processingPower,
                                                    List<Integer> bootingPower, long maxPower) {
    PriorityQueue<Integer> priorityQueue = new PriorityQueue<>((a, b) -> b - a);
    int maxLength = 0;
    int currentLength = 1;
    int startIdx = 0;
    int endIdx = 0;
    int currentSumProcessingPower = processingPower.get(0);
    priorityQueue.add(bootingPower.get(0));
    while (endIdx < processingPower.size()) {
        int currentBootingPower = priorityQueue.peek();
        long currentPower = currentBootingPower + ((long) currentSumProcessingPower) * currentLength;

        if (currentPower <= maxPower) {
            maxLength = currentLength;
            endIdx++;
            currentLength++;
        } else {
            currentSumProcessingPower -= processingPower.get(startIdx);
            priorityQueue.remove(bootingPower.get(startIdx));
            startIdx++;
            endIdx++;
        }

        if (endIdx < processingPower.size()) {
            priorityQueue.add(bootingPower.get(endIdx));
            currentSumProcessingPower += processingPower.get(endIdx);
        }
    }
    return maxLength;
}
https://leetcode.com/discuss/general-discussion/1700915
@hgulamm