You are working on an Amazon Data Center where you are required to reduce the amount of main memory consumption by the processes.
Given list of processes where each value representing memory consumption by the processes and given one variable m
representing number of processes to be removed. We need to delete m
number of processes from the list in contiguous manner and return minimum amount of main memory used by all the processes running after deleting contiguous segment of processes.
Function Description
Complete the function reduceMemoryUsage
in the editor.
reduceMemoryUsage
has the following parameters:
int[] processes
: an array of integers representing memory consumption by the processesint m
: the number of processes to be removed
Returns
int
: the minimum amount of main memory used after deleting a contiguous segment of processes
Example 1:
Input: processes = [10, 4, 8, 13, 20], m = 2
Output: 22
Explanation:Removing 13 and 20 as they are consuming large memory. The remaining processes consume 10 + 4 + 8 = 22 units of memory, which is the minimum possible.
1 < N < 1000000000
//size of the array1 < m < 100000
//contiguous segment of the array.1 < process[i] < 1000000000

input:
output: