Description
Solutions
Reduce Memory Usage
πŸ‘©β€πŸŽ“ NEW GRAD

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:

  1. int[] processes: an array of integers representing memory consumption by the processes
  2. int 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.

Constraints:
    • 1 < N < 1000000000 //size of the array
    • 1 < m < 100000 //contiguous segment of the array.
    • 1 < process[i] < 1000000000
Thumbnail 0
Testcase

Result
Case 1

input:

output: