FastPrepFastPrep
Problem Brief

Process Execution

INTERNOA
See Amazon online assessment and hiring insights

Amazon Web Services (AWS) has millions of servers that provide on-demand cloud computing platforms to the customers.

In one AWS center, there are nprocesses to be executed and m processors to execute them. The ith process requires power[i] for execution. A processor can provide power within its range minPower through maxPower[i]. Process i can be executed on processor j if minPower[j] ≤ power[i] ≤ maxPower[j].

Given the power consumption of n processes, the range of processor power in m processors, find:

  • the number of processes which can be executed on the processor
  • the sum of power consumed by the processes that it can serve
  • Function Description

    Complete the function processExecution in the editor.

    amazon-process-executionm processExecution has the following parameters:

    1. int power[n]: the power consumption of processes
    2. int minPower[m]: the minimum bounds of the ranges of processor power
    3. int maxPower[m]: the maximum bounds of the ranges of processor power

    Returns

    long_int[m][2]: the #th element of this array consists of 2 integers - the number of processes that lie within the range of the #th processor, and the sum of the power consumption of those processes.

    𓇢𓆸 🌷Credit to ʚ Mira ɞ ᯓᡣ𐭩。˚🌷

    1Example 1

    Input
    power = [7, 6, 8, 10], minPower = [6, 3, 4], maxPower = [10, 7, 9]
    Output
    [[4, 31], [2, 13], [3, 21]]
    Explanation
    Example 1 illustration
    The ans for each of the processors are [4, 31], [2, 13], [3, 21], where the first num represents the num of processes, and the second is the sum of power requirements. Return the 2-dimensional array, [[4, 31], [2, 13], [3, 21]]

    2Example 2

    Input
    power = [11, 11, 11], minPower = [8, 13], maxPower = [11, 100]
    Output
    [[3, 33], [0, 0]]
    Explanation
    The first processor (minPower[0] = 8, maxPower[0] = 11) can execute all 2 processes, and sum of powers = (11 + 11 + 11) = 33. The second processor (minPower[1] = 13, maxPower[1] = 100) cannot execute any of the processes since none of them lie in its range. Thus, its number of processes = 0 and power consumed = 0.

    Constraints

    Limits and guarantees your solution can rely on.

    • 1 ≤ n ≤ 12 * 10^5
    • 1 ≤ m ≤ 2 * 10^5
    • 1 ≤ power[i] ≤ 10^8
    • 1 ≤ minPower[i] ≤ maxPower[i] ≤ 10^8
    public long[][] processExecution(int[] power, int[] minPower, int[] maxPower) {
      // write your code here
    }
    
    Input

    power

    [7, 6, 8, 10]

    minPower

    [6, 3, 4]

    maxPower

    [10, 7, 9]

    Output

    [[4, 31], [2, 13], [3, 21]]

    Sign in to submit your solution.